Skip to content

Create resolver api#45

Merged
asmit-patil merged 4 commits intodevelopfrom
createResolver_api
Aug 14, 2020
Merged

Create resolver api#45
asmit-patil merged 4 commits intodevelopfrom
createResolver_api

Conversation

@jbertel2
Copy link
Copy Markdown
Contributor

I would like to point out a potential issue, hence creating a PR to discuss this

Comment thread normalize.js Outdated
@jbertel2
Copy link
Copy Markdown
Contributor Author

I still notice one case that doesn't work, probably related to schema generation.

When i query any union field for which the schema is generated by this branch, i get a graphql runtime error:

e.g.

query MyQuery {
  contentstackMediaCenter {
    videos {
      related_to {
        ... on Contentstack_event {
          title
        }
        ... on Contentstack_specialty {
          title
        }
        ... on Contentstack_product {
          title
        }
      }
    }
  }
}

results in

{
  "errors": [
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "contentstackMediaCenter",
        "videos",
        0,
        "related_to",
        0
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/gatsby/src/schema/schema.js:406:57",
        "    at completeAbstractValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/Users/jbertel2/Dev/jmc_frontend/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:591:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)"
      ]
    },
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "contentstackMediaCenter",
        "videos",
        1,
        "related_to",
        0
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/gatsby/src/schema/schema.js:406:57",
        "    at completeAbstractValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/Users/jbertel2/Dev/jmc_frontend/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:591:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)"
      ]
    },
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "contentstackMediaCenter",
        "videos",
        2,
        "related_to",
        0
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/gatsby/src/schema/schema.js:406:57",
        "    at completeAbstractValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/Users/jbertel2/Dev/jmc_frontend/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:591:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)"
      ]
    },
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "contentstackMediaCenter",
        "videos",
        3,
        "related_to",
        0
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/gatsby/src/schema/schema.js:406:57",
        "    at completeAbstractValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at /Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/Users/jbertel2/Dev/jmc_frontend/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:591:12)",
        "    at completeValueCatchingError (/Users/jbertel2/Dev/jmc_frontend/node_modules/graphql/execution/execute.js:495:19)"
      ]
    }
  ],
  "data": {
    "contentstackMediaCenter": {
      "videos": [
        {
          "related_to": [
            null
          ]
        },
        {
          "related_to": [
            null
          ]
        },
        {
          "related_to": [
            null
          ]
        },
        {
          "related_to": [
            null
          ]
        }
      ]
    }
  }
}

@jbertel2
Copy link
Copy Markdown
Contributor Author

Screenshot 2020-08-12 at 21 01 25

As can be seen in the above screenshot, some nodes don't have the expected internal field set...

Comment thread normalize.js
unionType = unionType.concat('_Union = ', unions.join(' | '));
types.push(unionType);

references.push({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe just pushing an object with just a parent and a uid is not sufficient to resolve queries afterwards, as demonstrated by the runtime error that is looking for an internal field with a type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while debugging, i noticed the related_to field being resolved by the default resolver and not the custom resolver we register...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like not all reference fields get our custom resolvers registered, but some fallback to the default resolver, with the runtime error as consequence. Not sure why yet...

Comment thread gatsby-node.js
});
});
groups.forEach(function (group) {
resolvers[group.parent] = (0, _defineProperty3.default)({}, group.field.uid, {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the root cause of the remaining problem. References and groups can have the same parent, or multiple references/groups can have the same parent. In these cases, we are overwriting the previous resolver...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See a7354b4 for a potential fix. This worked in my case...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jbertel2 for notifying this issue and fixing it. We appreciate your contribution here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants