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

Refactor query reading to use graphql-anywhere #747

Merged
merged 14 commits into from
Oct 6, 2016

Conversation

stubailo
Copy link
Contributor

@stubailo stubailo commented Oct 5, 2016

Part of #728
First step towards #617

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change

Still to do:

  • Fix remaining tests

@stubailo stubailo force-pushed the graphql-anywhere-refactor branch from 336561c to 8dda7fe Compare October 5, 2016 05:46
@helfer
Copy link
Contributor

helfer commented Oct 5, 2016

747 ✈️

@helfer
Copy link
Contributor

helfer commented Oct 5, 2016

Nice, so much complicated code removed! I will be even simpler once we stop converting from document to AC representation and back 😃

Copy link
Contributor

@helfer helfer left a comment

Choose a reason for hiding this comment

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

I think I need a code tour of graphql-anywhere 😉

ApolloError,
} from '../errors/ApolloError';

import graphql, {
Copy link
Contributor

@helfer helfer Oct 5, 2016

Choose a reason for hiding this comment

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

So many things called graphql now... I guess that's life.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change to graphql as graphqlAnywhere just to keep it classy.

fieldName: string,
objId: string,
args: any,
context: ReadStoreContext
Copy link
Contributor

Choose a reason for hiding this comment

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

are these the standard arguments to graphql-anywhere resolvers? Can you walk me through graphql-anywhere execution some time, so I understand why fieldName and objectId are there?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I would have expected to somehow get the parent somehow, but apparently that's not how it works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In graphql-anywhere, it's fieldName, rootValue, args, context. In this case, the rootValue just happens to be the object ID because that's what the parent resolver returns.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I see. I would have expected the parent to be the first argument. Maybe fieldName could be the last, since it's kind of like the info field in graphql?

Copy link
Contributor Author

@stubailo stubailo Oct 5, 2016

Choose a reason for hiding this comment

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

I guess it's the first argument because in regular GraphQL it's the first thing you write:

Query: {
  myFieldName: (root, args, context) => { ... }
}

In this case it's: (myFieldName, root, args, context) => { ... }

if (throwOnMissingField) {
handleFragmentErrors(fragmentErrors);
}
const result = graphql(readStoreResolver, doc, 'ROOT_QUERY', context, variables, mapper);
Copy link
Contributor

Choose a reason for hiding this comment

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

we could one-up graphql here and make the arguments named. (i know that's technically in graphql-anywhere, but I'm just putting all my thoughts here).

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the role of ROOT_QUERY here? It's kind of like a rootValue, but the resolvers don't return field names, so I'm unsure of how it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current implementation has the resolvers return either the ID of the related object or a scalar leaf field. So the initial root value is the ID of the root object, which is ROOT_QUERY.

@@ -88,9 +88,13 @@ export function storeKeyNameFromField(field: Field, variables?: Object): string
}

export function storeKeyNameFromFieldNameAndArgs(fieldName: string, args?: Object): string {
const stringifiedArgs: string = JSON.stringify(args);
if (args) {
const stringifiedArgs: string = JSON.stringify(args);
Copy link
Contributor

Choose a reason for hiding this comment

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

wait, did we never do anything about alphabetical ordering etc? Because we'll definitely get a cache miss if the order isn't the same, even if the values are semantically equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we might want to do that. Perhaps something to open a new issue about, since it doesn't necessarily need to be part of the refactor.

@stubailo stubailo merged commit 0acec91 into master Oct 6, 2016
@stubailo stubailo deleted the graphql-anywhere-refactor branch October 15, 2016 22:05
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants