-
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
Extend custom Types and Interfaces #20969
Comments
I think this can help you: https://learnwithjason.dev/advanced-graphql-techniques-in-gatsby At first glance everything looks good, I am also in the mobile when I get home I will see the detailed mind on my computer |
Can you share some minimal reproduction? It's hard to say what's going on without seeing source data and what you schema customization looks like |
I did, is part of the issue. Here you can see what I have: https://codesandbox.io/s/quirky-pare-bk01t |
@Jhony0311 Thanks for opening this! We lack documentation on how to create custom interfaces indeed. The missing piece in your sandbox is defining So what you could do is to define this interface separately: exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const blockInterface = schema.buildInterfaceType({
name: `Block`,
fields: {
kind: `String!`,
},
resolveType: value => value.kind,
})
const typeDefs = `
type PagesJson implements Node {
image: File @fileByRelativePath
example1: TriVideo
example2: ThoughtBlock
example3: TwoColumnWrapped
contentBlocks: [Block]
}
type TriVideo implements Block {
kind: String!
video1: String!
video2: String!
video3: String!
}
type ThoughtBlock implements Block {
kind: String!
orientation: String!
text: String!
}
type TwoColumnWrapped implements Block {
kind: String!
imageSide: String!
text: String!
images: [File!] @fileByRelativePath
}
`
createTypes([blockInterface, typeDefs])
} I've forked your codesandbox, so you can see a working version here: https://codesandbox.io/s/practical-monad-57x37 (also I don't think you need I hope it helps. |
That worked perfectly @vladar I appreciate it. I also appreciate the explanation, helped me a lot to understand what's happening and what I need to do to accomplish what I'm looking for. Is there any improvements to the docs that I could help with? I'm not a graphql expert myself but I'll be more than happy to jump on anything that could help people to get things clearer. |
@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): #13708 |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
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. Thanks again for being part of the Gatsby community! 💪💜 |
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:
But what I'm getting right now is:
Environment
I've created a minimal setup of my local within CodeSandbox
https://codesandbox.io/s/quirky-pare-bk01t
The text was updated successfully, but these errors were encountered: