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) {
      ... on recette_recette_Entry {
        category: recetteCategory { id, ... on recettes_Category { title } },
  • did you ever find an answer to this question? – Eric Jul 14 at 20:21
  • 1
    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 Jul 17 at 15:33
  • 1
    @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 Jul 18 at 18:09

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.

  • Awesome! Thank you so much for looking into this and linking! – Eric Jul 19 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.