-
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
[bug] ☂️ umbrella issue for schema customization issues #12272
Comments
The filters for ID fields now expect an ID as input where they previously wanted a string. This breaks certain queries, for instance: export const query = graphql`
query BlogPostTemplateQuery($id: String!) {
post: sanityPost(id: { eq: $id }) {
id
title
}
}
` Will report:
While it may be more correct to update the query to reflect this, it is a breaking change, so I thought I would report it. |
@rexxars Nice find! I assume we used to convert ID filters to String. I'll restore old behaviour. |
Released new version. |
Trying to query the schema in the resolver: exports.createResolvers = ({ createResolvers, schema }) => {
createResolvers({
MenuJson: {
someResolver: {
type: `String!`,
async resolve(source, args, context, info) {
const foo = await graphql(schema, `
{
allPageJson {
nodes {
id
}
}
}
`, {})
console.log(foo)
return 'WIP'
},
},
},
})
}
|
@NicoleEtLui For queries in the field resolver, use the methods provided on If you need to access to the schema, note that the |
Published |
@stefanprobst Thanks for the quick answer and all the great work you did ! |
Hi! For example, files are stored in JSON (without id field, assume the file name as id): Using the |
Hi !
will throw:
|
@NicoleEtLui Please update |
Published |
@LoicMahieu you can manually provide ids for the nodes, then you can do relationships by specifying |
Published |
Q: Is this use case suitable for I am using a remote CMS via Ideally, I'd like to add/link/join (?) these remote file nodes into the cms nodes from |
@skinandbones If I am understanding correctly, the short answer is "maybe but probably not quite yet". We do support extending field configs on types added from a third-party schema, so it is possible to add a field resolver to a type from your CMS schema with The problem is that |
@LoicMahieu Do you have an example project you can link to? |
@stefanprobst Yes, you understand correctly and the async issue makes sense. The example you linked is pretty similar to what I was expecting to do so I can give that a shot and see what happens. My plan is to run these file nodes through Is another viable approach to use |
@skinandbones sorry, i should have clarified: the part in the example i linked to is currently not yet working, exactly because of the issue that when the field resolver returns, the As for the second approach, I'd be interested in your findings -- it should be possible to query for the added remote |
@stefanprobst
|
Hey, I just read this blog post about schema customization and the birthday example kinda seemed strange to me. In the example you're creating a custom resolver, which tries to resolve a date field into a Date, and falls back to a bogus value (01-01-1970) if the input date is not a proper Date. If you ever actually had a date in a real system, you would never want to replace incorrect inputs with bogus data. You would want to flag them as unknown/incorrect with something like null values. The fact that null wasn't used in the example made me wonder: is there some kind of limitation in Gatsby/GraphQL wrt. null values? |
No. In GraphQL, you can explicitly set if a field should be nullable or not. More info here. |
@stefanprobst I got this working and it works with
Here's what I did ...
(This depends on me creating the file nodes with some fields, obviously. ) The optimal path (for my use case) will be to be able to use |
@skinandbones Very cool! Btw, you can use |
@stefanprobst - Thanks for your reply! Yes, it does, but the point of the plugin is that you should not have to use relative paths:
I've created a pull request with a fix that makes the returned relative path platform agnostic. I still don't know why it broke with 2.2.0. 🤷♀ |
@laradevitt ah, sorry, should have checked the readme.
This is very probably a regression in Gatsby, as with 2.2.0 type inference changed a bit -- but normalizing paths in |
I just created a new ticket related to schema customization. If it is better for me to close that and put it in this umbrella thread just let me know. Thanks! |
DescriptionArguments in a graphQL query don't work when using schema customization. After watching the learn with Jason stream on advanced GraphQL(broken up in multiple parts due to technical difficulties) I incorporated a lot of what was talked about into my theme. Steps to reproducerun this branch of my theme locally. Example 2Query for all posts and show their titles.
RESULT: works now query for all posts that are have a tag with slug "lorem-ipsum"
RESULT: empty nodes array. temporary workaround, possible reason why it doesn't work?Try to query a single BlogPost (picks first one by default if no arguments are given). It seems like the graphql arguments use data from the MdxBlogPost node rather than the eventual result after it runs its resolvers. Is my suspicion close? EnvironmentSystem: Additional notesRelevant parts of code are in |
@NickyMeuleman sorry haven't had time yet to look closely but it seems you are missing a link extension on the BlogPost interface. You define your tags: {
type: "[Tag]",
extensions: {
link: { by: "name" },
},
}, in the typedefs for the BlogPost interface you have: interface BlogPost @nodeInterface {
tags: [Tag]
} Does it work with interface BlogPost @nodeInterface {
tags: [Tag] @link(by: "name")
} |
Related: #16466 |
After adding your suggestion, querying n the future, will I be able to remove the |
@NickyMeuleman |
After #17284 got merged I tried removing the logic in my theme to work around this. Used Gatsby version: |
LekoArts suggested I ask this question more publicly than in the discord, since it might be a good topic for documentation. How do I describe Many to Many relationships with createSchemaCustomization? The use cases I have are the following:
|
@Everspace Try this for 1. add to exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = [
schema.buildObjectType({
name: 'Store',
fields: {
products: {
type: "[Product]",
extensions: {
link: {},
},
},
},
interfaces: ['Node'],
}),
schema.buildObjectType({
name: 'Product',
fields: {
stores: {
type: "[Store]",
extensions: {
link: {},
},
},
},
interfaces: ['Node'],
}),
]
createTypes(typeDefs)
} |
@NickyMeuleman Do you mean you don't get results or that you don't see fields in input object? |
When I comment out the
has the same (non-empty) result as the same query with the order set to |
Are there any examples out there for how to handle schema customization for an optional image coming from Contentful? |
Been a while since Schema Customisation has been released and things are stable. I think it's time to close this issue 🙂 Incredible work @freiksenet and @stefanoverna ❤️ Folks, if you're having trouble related to Schema Customisation, let's open independent issues. Thanks! |
This is a meta issue for all the issues with 2.2.0, that were introduced by the schema refactoring.
What?
See the blog post for the details about why we did the refactoring and what's it all about.
See the release blog post for release notes and final updates.
How?
Install latest version of Gatsby and try running your site. Hopefully it will all just work. If you want, you could also try the two new APIs (
createTypes
andcreateResolvers
).Changelog
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
FilterInput
types are now not prefixed by output type, reducing proliferation of types[email protected]
@dontInfer(noDefaultResolvers: false)
actually workscreateResolvers
resolversinfo.originalResolver
is available even if there is no resolver on original field[email protected]
[email protected]
The text was updated successfully, but these errors were encountered: