-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot get type name from ThunkComposer #33957
Comments
Hi! Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it. If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look. Thanks for using Gatsby! 💜 |
@LekoArts Thanks for checking this issue. I just attached the minimal reproduction. Do I need to add the https://github.com/marcomiduri/gatsby-issue-reproduction |
@marcomiduri Yes, if the |
Hi @graysonhicks - I have a similar issue: I am using interface SubPage {
contentful_id: String!
node_locale: String!
slug: String
subPages: [SubPage]
dynamicSubPageKeys: [String]
}
type ContentfulPage implements SubPage {
subPages: [SubPage]
}
type ContentfulPureContent implements SubPage {
subPages: [SubPage]
} Everything works fine with Apparently, it has something to do with adding an interface - or even fixing a type on an existing (inferred) type. It would be great if you could look into it ... |
@graysonhicks I have committed the |
Hi, @LekoArts @graysonhicks Just wanted to check if this issue is still progressing |
I haven't had a chance to retest, but I wonder if this is related to using |
You can't do this with engines as it doesn't support bundling these files: You'll need to put the definition either in a JS file and import it or directly put it into gatsby-node.js (So this is not a bug but a limitation) |
@LekoArts @graysonhicks Thanks for your immediate response. I just removed |
Referencing those issues: I'm not really understanding why you're redefining the types there as it already correctly creates a union: But anyways, if you want to have a custom union, you need to define it this way: exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const typeDefs = `
type SanityBifold {
id: ID!
_type: String!
_key: String!
}
type SanityCallToAction {
id: ID!
_type: String!
_key: String!
}
type SanityPage implements Node {
contentBlocks: [ContentBlocks]
}
`
const ContentBlocks = schema.buildUnionType({
name: `ContentBlocks`,
types: [`SanityBifold`, `SanityCallToAction`],
resolveType: (value, info) => {
if (value._type === `bifold`) {
return `SanityBifold`
} else {
return `SanityCallToAction`
}
}
})
createTypes(typeDefs)
createTypes([ContentBlocks])
} Then it'll also work: Successfully built: So I think the validation is doing it's job here and catching a user error, not an error in Gatsby itself. So @jroehl I'm suspecting your schema definitions are also incorrect. |
@LekoArts Thank you very much for this code snippet. But I have to define My last commit URL: marcomiduri/gatsby-issue-reproduction@a6a6081 Thank you |
Why do you have to do that? So in exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const typeDefs = `
type SanityBifold implements ContentBlock {
_type: String!
_key: String!
}
type SanityCallToAction implements ContentBlock {
_type: String!
_key: String!
}
type SanityPage implements Node {
contentBlocks: [ContentBlocks]
}
`
const contentBlockInterface = schema.buildInterfaceType({
name: `ContentBlock`,
fields: {
_type: `String!`,
_key: `String!`,
},
resolveType: value => value._type,
})
const contentBlocksUnion = schema.buildUnionType({
name: `ContentBlocks`,
types: [`SanityBifold`, `SanityCallToAction`],
resolveType: (value) => {
if (value._type === `bifold`) {
return `SanityBifold`
} else {
return `SanityCallToAction`
}
}
})
createTypes([contentBlockInterface, typeDefs, contentBlocksUnion])
} I'm not sure why you need ContentBlock to be an Interface and what you want to do with it. Depending on how you want to use it your configuration still might be wrong. |
@LekoArts I have defined a fragment called ContentBlockBase and used it on all block fragment like below: fragment ContentBlockBase on ContentBlock {
_type
_key
}
fragment Blocks on ContentBlocks {
...ContentBlockBase
} So we don't need to write I have run it using |
I have minimal repro for error like this to happen during regular schema building in https://github.com/pieh/i33957-mini/blob/c8a1c27fcd8a6400fc2585daded1387c116e5847/gatsby-node.js Not yet sure where the problem is, but this at least it seems to simulate what happens when engines validation happen and should make it easier to debug moving forward (it doesn't have any plugins other than internals so there is less "noise" in there) |
Preliminary Checks
Description
I have enabled server-side rendering and DSG for our shop product pages. Page fetches the product review information in real-time using server-side rendering. After I enable server-side rendering, I am getting this error on build process.
Error: Cannot get type name from ThunkComposer({ _thunk: [function ], _typeName: "ContentBlock" })
This
ContentBlock
is a custom schema interface that I created using thecreateSchemaCustomization
API.FYI, it's working fine on development mode.
Reproduction Link
Minimal Reproduction Repository
Steps to Reproduce
gatsby build
Expected Result
Build should be done without any problems
Actual Result
Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: