-
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
[meta] Gatsby GraphQL Roadmap #12510
Comments
Awwww yeah. This means soon, I won't have to dig into the Gatsby store to get the schema anymore? |
Would be great to see if we can deal with the upstream issues around including GraphQL fragments in GraphiQL. |
@jserrao Could you link to the issue? |
@freiksenet - I'm not sure anything is broken, but functionally it's non optimal DX. The most Gatsby-related issue is around On a Gatsby page, they would do something like this:
If you get that working, that's a nice little confidence boost when you're trying out a new tool. But then In GraphiQL, you can't use
Obviously not the end of the world, but if we can get fragments into GraphiQL somehow, that would be a win. |
I'm so into this new work! I've run into two things while playing with this.
Util function for making root query resolversFor example, if I create a exports.sourceNodes = ({ actions: { createTypes }, schema, reporter }) => {
reporter.info('Adding the `Post` and `Author` types to the schema.');
createTypes(`
type Post implements Node {
title: String!
}
`);
}; Gatsby will automatically create a If I want to implement a custom resolver, I currently need to provide all of that stuff, which feels cumbersome and likely to cause issues over time. (E.g. internals change; does that break all custom resolvers in userland?) To address this, I'd love to see a utility function that does something like this: function createGatsbyRootResolver(nodes) {
// TODO do stuff to handle distinct and group fields
return {
nodes,
edges: nodes.map(node => ({ node })),
totalCount: nodes.length,
// ...
}
} In userland, it could be supplied as a helper: exports.createResolvers = ({ createResolvers, createGatsbyRootResolver }) => {
createResolvers({
Query: {
post: {
async resolve(_, args, context) {
const post = await context.nodeModel.runQuery({
query: args,
type: 'MarkdownRemark',
firstOnly: true
});
return mdToPost(post);
}
},
allPost: {
async resolve(_, args, context) {
const posts = await context.nodeModel
.runQuery({
query: args,
type: 'MarkdownRemark'
});
// Turns the array into a format compatible with the root resolver schema
return createGatsbyRootResolver(posts);
}
}
}
});
}; If we don't do this, every custom type starts with broken queries by default. Best practice for custom node IDsRight now, the In a perfect world, we'd auto-generate these somehow. At minimum, we should have a canonical example of how to generate these IDs (and any other fields Gatsby requires and/or assumes will exist in documentation). |
@jlengstorf I think with interfaces the id thing will be a bit easier because they'll always have the same ids as nodes of the underlying backing types. Also interfaces will get all the stuff inside the resolver automatically, so you wouldn't need to define it. |
If I'm understanding it correctly; It would be nice if a user could just drop a |
@freiksenet I see directives under "Nice to have things". Is there any way now to add custom directives? Possibly by exposing the schema composer? gatsby/packages/gatsby/src/schema/schema-composer.js Lines 10 to 11 in 07e69be
|
@angeloashmore We don't plan to expose the schema composer directly. Next step is to expose some internals via extension/directive - for example to define foreign-key relations on fields. Once we are happy with the API for this, it would not be very hard to also allow registering custom extension/directive handlers. |
@angeloashmore For custom directives, this is how it could look like: #13623 |
Closing this as it's out of date and mostly done. |
With #12272 being close to be shipped, it's nice to have a more detailed roadmap on what we want to do next. This issue serves as such roadmap. Issues not in priority order.
Documentation issues
nodes
)createRemoteFileNode
in resolvers)Core improvements
@date
,@fileByRelativePath
)Nice to have things
@file
or@relativeFile
createTypes
based on current inferred schemaThe text was updated successfully, but these errors were encountered: