0

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');
  }
};
Sawyer
  • 221
  • 3
  • 6

1 Answers1

2

Well, looks like I figured it out (sigh)

Problem is the dummy resolve function I wrote for the non-nested fields didn't return. Behold the fix:

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');
    return true;
  }
};

I'll leave this here in case anyone else runs into the same thing.

Sawyer
  • 221
  • 3
  • 6