'GraphQL (node over REST) Nested Arguments Missing from Arguments Object

I have a GraphQL question. I am running it over a REST API and all appears to be working apart from nested arguments.

I have this query...

query {
    Document(reference: "123ABC") {
        id
        reference
        Parts(id: "1212") {
            id
            content
        }
    }
}

And this is against the following schema...

schema {
    query: Query
}

type Document {
    id: ID
    reference: String
    name: String
    Parts(id: ID): [Part]
}

type Part {
    id: ID
    content: String
}
    
type Query {
    Document(id: ID, reference: String): Document!
    Documents: [Document]
    Part(id: ID): Part!
    Parts: [Part]
}

Now for the most part this setup is working, i can use a reference or ID to match a single document, or get all documents and also have nested parts. The issue is when i try to use arguments on the nested 'Parts'. The id I am setting on Parts model is not coming through to the args on the nested rootValue.

const rootValue = {
    Document: async (args) => await document.model(args),
    Documents: async (args) => await document.models(args),
    Part: async (args) => await part.one(args),
    Parts: async (args) => await part.many(args)
};
    
return graphql({ source: request.body.query, variableValues: 
request.body.variables, schema, rootValue });

So i pass in schema, variableValues is in case i want to send in variables separately (also not working) in this case undefined.

args passed into each model only has the following in it...

{
   "reference": "123ABC"
}

With no sign of the other argument from Parts(id: "123"), anyone have any idea where im messing up, why the other argument would be missing, am i looking in the wrong place...

I can dump out another var from the methods on rootValue, looks like a definition that graphql is using, the values are in there deep inside i can search for the value, but why they not being passed to args?

thanks people!

Paul



Solution 1:[1]

OK, I had a thought, and did this...

    Document: async (args) => {
        console.log(4, JSON.stringify(args))
        return { 
            ...await document.model(args),
            Parts: async (ffs) => {
                console.log(5, JSON.stringify(ffs));
            }
        }
    },

And up it popped.... i see whats happening now, its passing the args out based on location in the rootValue.

I get the first arg in the first console log only and the second in the second console log only...

Documentation around the web is a little sparse in this.

I think i need to re-jig my code now, to sub query on nested models instead of returning one big nested dataset.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul