Nodes
A common scenario into which you will run often is to query a node together with certain field. We have already seen a couple of things that can give a good overview on how to do this. Let's take our example of the "Article" type again and query some fields like the id
, the label
but also the custom field creator
which is just a normal text field.
Before you start, make sure to read the introduction and how to add a custom schema, only after that you should start adding resolvers and extending your schema with your own types.
Add the schema declaration
The first step, as seen in the introduction, is to add the types and fields in the schema. You can add this directly into schema string in your own schema implementation (src/Plugin/GraphQL/Schema/SdlSchemaMyDrupalGql.php
).
Now we have an "Article" type in the schema with three fields id
, label
and our custom field creator
. The next step is to add resolvers for each of them.
Adding resolvers
To add the resolvers we go to our schema implementation and call the appropriate data producers inside the getResolverRegistry
method. Because our types are extending a common NodeInterface
we need to also tell what to resolve for a particular type, otherwise it could be an Article or a Page.
Last updated