Pass variableName: value in the separate, transport-specific (usually JSON) variables dictionary.Declare $variableName as one of the variables accepted by the query.
Replace the static value in the query with $variableName.When we start working with variables, we need to do three things: Instead, GraphQL has a first-class way to factor dynamic values out of the query, and pass them as a separate dictionary.
#How to get core fragments code
It wouldn't be a good idea to pass these dynamic arguments directly in the query string, because then our client-side code would need to dynamically manipulate the query string at runtime, and serialize it into a GraphQL-specific format. But in most applications, the arguments to fields will be dynamic: For example, there might be a dropdown that lets you select which Star Wars episode you are interested in, or a search field, or a set of filters. So far, we have been writing all of our arguments inside the query string. In the same way, GraphQL query and mutation names, along with fragment names, can be a useful debugging tool on the server side to identify Think of this just like a function name in your favorite programming language.įor example, in JavaScript we can easily work only with anonymous functions, but when we give a function a name, it's easier to track it down, debug our code,Īnd log when it's called. When something goes wrong (you see errors either in your network logs, or in the logs of your GraphQL server) it is easier to identify a query in your codebase by name instead of trying to decipher the contents. It is only required in multi-operation documents, but its use is encouraged because it is very helpful for debugging and server-side logging. The operation name is a meaningful and explicit name for your operation.
The operation type is required unless you're using the query shorthand syntax, in which case you can't supply a name or variable definitions for your operation. The operation type is either query, mutation, or subscription and describes what type of operation you're intending to do.