graphqlOperation
is mentioned quite a bit in the amplify docs. It comes up for mutations, queries, and subscriptions in various places.
import { API } from 'aws-amplify';import { createTodo, updateTodo, deleteTodo } from './graphql/mutations';const todo = { name: "My first todo", description: "Hello world!" };/* create a todo */await API.graphql(graphqlOperation(createTodo, {input: todo}));/* update a todo */await API.graphql(graphqlOperation(updateTodo, { input: { id: todoId, name: "Updated todo info" }}));/* delete a todo */await API.graphql(graphqlOperation(deleteTodo, { input: { id: todoId }}));
but if we look at the source code, it doesn't do anything but obscure the object that's being passed in to people who are unfamiliar with it.
My suggestion: don't use it unless you're 100% bought into amplify codegen. It doesn't make sense if you're writing your own queries.
The alternative is
API.graphql({query: `query GetWorkspace($id: String!) {workspace(id: $id) {idname}}`,variables: { id: "someid" },});