question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend custom Types and Interfaces

See original GitHub issue

Summary

Hey Gatsby people,

I’m starting a project where my data source is a set of JSON files. In order to make them a bit more robust, I would like to get them extender using custom types. I already put something in place for custom types nested inside of a field of my JSON but the things are not working for me when I tried to do an interface for an array.

I was looking into the documentation for schema customization (https://www.gatsbyjs.org/docs/schema-customization/) but the portion for interfaces is not as detailed as I would like in order to complete the setup myself.

I’m thinking that I might be missing to create one resolver for the field that exposes the interface but not sure what is the best way to go for it.

My expectation is to get something like this as an output of the Graphql API:

{
    "__typename": "TriVideo",
    "kind": "TriVideo",
}

But what I’m getting right now is:

{
  "errors": [
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "pagesJson",
        "contentBlocks",
        0
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at typeComposer.setResolveType.node (/sandbox/node_modules/gatsby/dist/schema/schema.js:471:57)",
        "    at completeAbstractValue (/sandbox/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/sandbox/node_modules/graphql/execution/execute.js:495:19)",
        "    at /sandbox/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/sandbox/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/sandbox/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/sandbox/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/sandbox/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/sandbox/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/sandbox/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/sandbox/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:591:12)",
        "    at /sandbox/node_modules/graphql/execution/execute.js:492:16"
      ]
    },
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "pagesJson",
        "contentBlocks",
        1
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at typeComposer.setResolveType.node (/sandbox/node_modules/gatsby/dist/schema/schema.js:471:57)",
        "    at completeAbstractValue (/sandbox/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/sandbox/node_modules/graphql/execution/execute.js:495:19)",
        "    at /sandbox/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/sandbox/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/sandbox/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/sandbox/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/sandbox/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/sandbox/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/sandbox/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/sandbox/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:591:12)",
        "    at /sandbox/node_modules/graphql/execution/execute.js:492:16"
      ]
    },
    {
      "message": "Cannot read property 'type' of undefined",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "pagesJson",
        "contentBlocks",
        2
      ],
      "stack": [
        "TypeError: Cannot read property 'type' of undefined",
        "    at typeComposer.setResolveType.node (/sandbox/node_modules/gatsby/dist/schema/schema.js:471:57)",
        "    at completeAbstractValue (/sandbox/node_modules/graphql/execution/execute.js:652:21)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValueCatchingError (/sandbox/node_modules/graphql/execution/execute.js:495:19)",
        "    at /sandbox/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/sandbox/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/sandbox/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValueCatchingError (/sandbox/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/sandbox/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/sandbox/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/sandbox/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/sandbox/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/sandbox/node_modules/graphql/execution/execute.js:591:12)",
        "    at /sandbox/node_modules/graphql/execution/execute.js:492:16"
      ]
    }
  ],
  "data": {
    "pagesJson": {
      "contentBlocks": [
        null,
        null,
        null
      ]
    }
  }
}

Environment

I’ve created a minimal setup of my local within CodeSandbox https://codesandbox.io/s/quirky-pare-bk01t

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marcysuttoncommented, Jan 29, 2020

@Jhony0311 we have Using Schema Customization coming up as a workflow to evaluate next quarter. If there are things you feel could be improved in the docs in the meantime, we would welcome a PR! Another way to contribute would be to get a jump start on the workflow evaluation as outlined here (# 15): https://github.com/gatsbyjs/gatsby/issues/13708

0reactions
github-actions[bot]commented, Feb 29, 2020

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending object-like types with interfaces in TypeScript
Extending multiple interfaces refers to the concept of composition where the interface is designed to extend attributes it needs. It differs ...
Read more >
Possible to extend types in Typescript? - Stack Overflow
UPDATE for TypeScript 2.2, it's now possible to have an interface that extends object-like type, if the type satisfies some restrictions:
Read more >
TypeScript Extend Interface
Interfaces extending classes ... TypeScript allows an interface to extend a class. In this case, the interface inherits the properties and methods of...
Read more >
Handbook - Interfaces - TypeScript
Interfaces are capable of describing the wide range of shapes that JavaScript objects can take. In addition to describing an object with properties,...
Read more >
TypeScript Class: Extending Classes & Interfaces - Pluralsight
The callback function must accept two parameters of type boolean and string. An example of implementing the IEngine interface using TypeScript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found