Tuesday, 6 June 2017

Graphql resolve function on nested fields not getting called

With this query, in graphQL, the resolve function on desiredSubfield is not getting called, and the query returns null. How can I properly resolve a nested field?

Query:

{
    "query": "query ($requiredArg: String!, $anotherArg: String) { user(requiredArg: $requiredArg) { desiredSubfield(anotherArg: $anotherArg) { _id name} } }",
    "variables": {
        "requiredArg": "someString",
        "anotherArg": "anotherString"
    }
}

Associated Object:

export default {
  type: userType,
  args: {
    requiredArg: {
      name: 'requiredArg',
      type: new GraphQLNonNull(GraphQLString),
    },
  fields: () => {
    return {
      desiredSubfield: {
        type: subfieldType,
        args: subfieldType.args,
        resolve(source, params, root, ast) {
          console.log('subfield resolve is hit');
          return fetchUser();
        },
      },
    };
  },
  resolve(source, params, root, ast) {
    console.log('in main resolve');
  }
};



via Sawyer

No comments:

Post a Comment