![]() ![]() Try editing the variables above to instead pass true for withFriends, and see how the result changes. Default variables #ĭefault values can also be assigned to the variables in the query by adding the default value after the type declaration. The schema language is explained in detail on the Schema page. ![]() To learn more about the syntax for these variable definitions, it's useful to learn the GraphQL schema language. But if the field you are passing the variable into requires a non-null argument, then the variable has to be required as well. In the case above, since there isn't an ! next to the Episode type, it's optional. Variable definitions can be optional or required. Learn more about input object types on the Schema page. So if you want to pass a complex object into a field, you need to know what input type that matches on the server. It lists all of the variables, prefixed by $, followed by their type, in this case Episode.Īll declared variables must be either scalars, enums, or input object types. It works just like the argument definitions for a function in a typed language. The variable definitions are the part that looks like ($episode: Episode) in the query above. This is also in general a good practice for denoting which arguments in our query are expected to be dynamic - we should never be doing string interpolation to construct queries from user-supplied values. Now, in our client code, we can simply pass a different variable rather than needing to construct an entirely new query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |