<p>So after reaching out to Craft's support, they very kindly pointed out that I had great timing because they had just launched new documentation pages outlining details on how to create GraphQL resolvers.</p>
<p>Documentation about the required Interfaces:
<a href="https://craftcms.com/docs/3.x/extend/graphql.html#interfaces" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/extend/graphql.html#interfaces</a></p>
<p>Documentation on the folder structure of such a system and the events emitted by GraphQL to allow modifying simple queries before they're sent back to the client:
<a href="https://craftcms.com/docs/3.x/extend/graphql.html#interfaces" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/extend/graphql.html#interfaces</a></p>
<p>Even though I answered to my own question over time, I think this should be the approved answer since this is official documentation in the end.</p>

CC BY-SA 4.0
2021-07-19T19:23:47.833Z
Awesome! Thank you so much for looking into this and linking!
Eric
CC BY-SA 4.0
2021-09-10T17:16:53.703Z
You may find this of use:

https://github.com/lsst-epo/craft3-nested-entries-graphql-queries

It's a graphQL Craft plugin I created with the help of the Craft community, maybe it fits your use case - if anything it's an example of functioning code with not a custom resolver, but custom query.
Eric
CC BY-SA 4.0
2021-07-18T18:12:16.957Z
2021-07-18T18:12:16.957Z
davidwebca
<p>I am currently editing a headless VueJS + Craft + GraphQL website and the client asks me to add a Recipe section. I found <a href="https://plugins.craftcms.com/recipe" rel="nofollow noreferrer">https://plugins.craftcms.com/recipe</a> which is great, but when I add the field to my section and I write my GraphQL query, it doesn't seem to be able to resolve the field type of Recipe.</p>
<p>Here's what I get in &quot;debugMessage&quot; from the GraphQL api.</p>
<p><code>Expected a value of type \&quot;String\&quot; but received: instance of nystudio107\\recipe\\models\\Recipe</code></p>
<p>Now, if I understand right, the problem either that I'm not specifying the type correctly when I query my content or that I would need to write a custom resolver to &quot;unpack&quot; the plugin's class into scalar types. So that brings me to the question: is it possible to hook into Craft's resolving mecanism and unpack custom fields?</p>
<p>I also am already using the elements api for some other endpoints and that might be what I end up doing to solve the problem, but I'd love to stay in GraphQL for consistency if possible.</p>
<p>Thank you everyone for your time!</p>
<p>--</p>
<p>For reference, here's my query and the &quot;recetteContenu&quot; field is the recipe field.</p>
<pre class="lang-javascript prettyprint-override"><code>let query = `
  query FetchEntries($lang: [String], $slug: [String]) {
    entry (section: &quot;recette&quot;, site: $lang, slug: $slug) {
      title,
      ... on recette_recette_Entry {
        category: recetteCategory { id, ... on recettes_Category { title } },
        recetteContenu
      }
    }
  }
`;
</code></pre>

CC BY-SA 4.0
2021-07-14T20:21:01.960Z
did you ever find an answer to this question?
Eric
CC BY-SA 4.0
2021-07-17T15:33:12.127Z
Sorry, sadly no. Since I was working on a schedule, I had to resolve myself working with the elements API for that part sadly. I'd love to learn how to do it though and I have 100+ hours to put into that same project later this year so if I can learn how before then, I could refactor my code at that moment.
davidwebca
CC BY-SA 4.0
2021-07-18T18:09:17.233Z
@Eric Just as a follow up, I reached out to Craft's support and they told me that I had great timing because they created new documentation pages recently outlining how to do exactly this. I'll put the links in an answer.
davidwebca
<graphql>
Is it possible to write a custom GraphQL resolver for Craft?
# Is it possible to write a custom GraphQL resolver for Craft?

(Asked by: username_0 on 2021-04-12)

I am currently editing a headless VueJS + Craft + GraphQL website and the client asks me to add a Recipe section. I found https://plugins.craftcms.com/recipe which is great, but when I add the field to my section and I write my GraphQL query, it doesn't seem to be able to resolve the field type of Recipe.
Here's what I get in "debugMessage" from the GraphQL api.
Expected a value of type \"String\" but received: instance of nystudio107\\recipe\\models\\Recipe
Now, if I understand right, the problem either that I'm not specifying the type correctly when I query my content or that I would need to write a custom resolver to "unpack" the plugin's class into scalar types. So that brings me to the question: is it possible to hook into Craft's resolving mecanism and unpack custom fields?
I also am already using the elements api for some other endpoints and that might be what I end up doing to solve the problem, but I'd love to stay in GraphQL for consistency if possible.
Thank you everyone for your time!
--
For reference, here's my query and the "recetteContenu" field is the recipe field.
let query = `
  query FetchEntries($lang: [String], $slug: [String]) {
    entry (section: "recette", site: $lang, slug: $slug) {
      title,
      ... on recette_recette_Entry {
        category: recetteCategory { id, ... on recettes_Category { title } },
        recetteContenu
      }
    }
  }
`;

**Tags:** graphql
> **Comments:**
> **username_1**: did you ever find an answer to this question?  
> **username_0**: Sorry, sadly no. Since I was working on a schedule, I had to resolve myself working with the elements API for that part sadly. I'd love to learn how to do it though and I have 100+ hours to put into that same project later this year so if I can learn how before then, I could refactor my code at that moment.  
> **username_0**: @Eric Just as a follow up, I reached out to Craft's support and they told me that I had great timing because they created new documentation pages recently outlining how to do exactly this. I'll put the links in an answer.  

---

## 1 answers

### Answer by username_0 on 2021-07-18. Score: 3

So after reaching out to Craft's support, they very kindly pointed out that I had great timing because they had just launched new documentation pages outlining details on how to create GraphQL resolvers.

Documentation about the required Interfaces:
<https://craftcms.com/docs/3.x/extend/graphql.html#interfaces>

Documentation on the folder structure of such a system and the events emitted by GraphQL to allow modifying simple queries before they're sent back to the client:
<https://craftcms.com/docs/3.x/extend/graphql.html#interfaces>

Even though I answered to my own question over time, I think this should be the approved answer since this is official documentation in the end.

> **Comments:**
> **username_1**: Awesome! Thank you so much for looking into this and linking!  
> **username_1**: You may find this of use:  https://github.com/lsst-epo/craft3-nested-entries-graphql-queries  It's a graphQL Craft plugin I created with the help of the Craft community, maybe it fits your use case - if anything it's an example of functioning code with not a custom resolver, but custom query.  

---

