Skip to content
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

[WIP] graphql schema refactor #10995

Closed
wants to merge 124 commits into from

Conversation

stefanprobst
Copy link
Contributor

See #4261

Copy link
Contributor

@freiksenet freiksenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a quick look. I'm not trying to nitpick on changes, but I really would want to try to make this PR as small as possible and to change as little things is possible, because then we can:

  • Test in efficiently
  • Minimize api surface changes to the users
  • Do other good changes in subsequent PRs.

I'm really happy to help with that, but it's a massive change, so I'd be really helpful if you briefly explain some of the changes.

Thanks!

@@ -1,90 +0,0 @@
const _ = require(`lodash`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the change to node-tracking?

@@ -170,3 +170,65 @@ emitter.on(`DELETE_PAGE`, action => {
const node = getNode(nodeId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add typeDefs to all Gatsby plugins? Which ones do we add this to? Can we do it in separate PRs while keeping basic functionality working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While not necessary I think it's a good idea to add typedefs to internal plugins, since there's no need to infer those types on every run. Also, we should rethink the status of the File type, which we currently treat as if it were internal (e.g. we auto-infer File fields), but rely on a not-internal plugin to handle.

@@ -1,97 +0,0 @@
const runSift = require(`../run-sift`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were those tests moved somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, but there are tests in schema/query/sift

@@ -2,55 +2,44 @@ const Redux = require(`redux`)
const _ = require(`lodash`)
const fs = require(`fs`)
const mitt = require(`mitt`)
const stringify = require(`json-stringify-safe`)
const v8 = require(`v8`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you summarize the changes here and why they were required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed unrelated, see PR #10732

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other changes in get-nodes-for-query that are perf-related and could easily be extracted: (i) also cache during bootstrap, not only in production, and (ii) first check if there actually are resolvers to manually call, before iterating over all nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And use a separate redux namespace for nodesByType.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, would be great if you could extract those changes, I think they are useful outside of the context of this pr :)

@@ -0,0 +1,179 @@
const { TypeComposer, schemaComposer } = require(`graphql-compose`)
const { SchemaDirectiveVisitor } = require(`graphql-tools`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] I'd rather test such things by running GraphQL queries, rather than by calling resolvers.

@@ -0,0 +1,19 @@
const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's expose this to the user in some way, as discussed before in the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be on context, see query-runner

findOne,
paginate,
} = require(`./resolvers`)
const link = require(`./link`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to "getByField"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good


// FIXME: Handle array of arrays
// Maybe TODO: should we check fieldValue *and* info.returnType?
const link = ({ by }) => (source, args, context, info) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a bit magical as a general resolver, what about eg Unions or Interfaces? I don't mind the directive though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, Unions need support from graphql-compose though

@stefanprobst
Copy link
Contributor Author

@freiksenet Thanks for your comments! I think I should start by saying that I have been working on this branch as a hobby learning project, and literally the first thing I did was delete everything in the schema/ folder and start from scratch. So it's probably best to not base the schema refactor off of this, but view it more as a working prototype to take some ideas from, especially if we want to keep this as minimally invasive as possible.
I'm really motivated to help with that (and also appreciate feedback) but let's close this and do it properly?

As for the rest, comments inline.

@freiksenet
Copy link
Contributor

@stefanprobst Sounds good :) I think the minimal PR would have graphql-compose backed schema, addTypeDefs and addResolvers functions and maybe the model layer. I probably won't have much time to work on it next week, but I can start or help with it after that. Looking forward to the call!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants