Skip to content Skip to sidebar Skip to footer

Graphql How To Do A Join Request Instead Of Many Sequential Request?

I have two GraphQL type: type Author { id: String! name: String! } type Book { id: String! author: Author! name: String! } In my database, it is implemented by a foreig

Solution 1:

I just discovered that in the fourth parameter gived at the resolver, there where an array of the queried fields: info.fieldNodes[0].selectionSet.selections.

I didn't found any documentation about this, and I wonder what represent the fieldNodes array... (and dont like to access the first element that way without knowing it...).

The selections object contains an array like this:

[
  {
    kind:'Field',
    alias:undefined,
    name: { kind:'Name', value:'id', loc: [Object] },
    arguments: [],
    directives: [],
    selectionSet:undefined,
    loc: { start:36, end:38 }
  },
  {
    [...]
  },
  ...
]

Here, the value: 'id' match the name of the queried field of the related author.

If I go a level deeped, the selectionSet: undefined becomes an object and the pattern repeat itself recursively...

Post a Comment for "Graphql How To Do A Join Request Instead Of Many Sequential Request?"