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

Compound key support in federation #1011

Merged
merged 2 commits into from
Feb 6, 2020
Merged

Conversation

lizfaubell
Copy link
Contributor

@lizfaubell lizfaubell commented Feb 5, 2020

Compound keys aren't currently supported in the federation plugin, but are allowed per the Apollo spec. This patch adds support by modifying the federation plugin to handle a list of key fields on an entity rather than a single top-level key field. It will now look for "findEntityNameByKeyField1AndKeyField2..." in the resolver, rather than the original "FindEntityNameByKeyField". The change does not support more complicated FieldSets in the key, such as nested selections.

We are using this internally with Go services that use compound keys in federation.

References:

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs) - I didn't find anything docs specific to federation.

Summary:
Compound keys are not yet supported for federation in gqlgen. This diff adds support by modifying the federation plugin to handle a list of key fields on an entity rather than a single top-level key field. It will now look for "find<EntityName>By<KeyField1><KeyField2>..." in the resolver, rather than the original "Find<EntityName>By<KeyField>". The federation plugin does not yet support more complicated FieldSets in the key, such as nested selections.

References:
- Apollo federation spec: https://www.apollographql.com/docs/apollo-server/federation/federation-spec/
- Selection sets: https://graphql.github.io/graphql-spec/draft/#sec-Selection-Sets

Will update https://phabricator.khanacademy.org/D59469 with multiple key changes.

Test Plan:
- Tested Go GQL services using both single- and multiple-key federated types (assignments and content-library in webapp/services)
- Ran gqlgen on non-federated services in webapp to ensure regular generation still works (donations service)
- WIP: creating unit tests; will submit as separate diff

Reviewers: briangenisio, dhruv, csilvers, O4 go-vernors

Reviewed By: dhruv, csilvers, O4 go-vernors

Differential Revision: https://phabricator.khanacademy.org/D59569
Summary: The current federation test schema only has types with single keys (or no keys). Adding a type with multiple keys, including one non-String key, to test compound key federation code gen.

Test Plan: - go test

Reviewers: csilvers, miguel

Differential Revision: https://phabricator.khanacademy.org/D60715
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 65.737% when pulling 6540163 on Khan:compound-keys into b941b97 on 99designs:master.

@vektah
Copy link
Collaborator

vektah commented Feb 6, 2020

Nice, another incremental. Any thoughts @marwan-at-work ?

@marwan-at-work
Copy link
Contributor

Looks awesome! I'll clone the branch and give it a try as soon as I can.

Feel free to merge in the mean time if it looks good to everyone 👍

@vektah vektah merged commit 0fe1af8 into 99designs:master Feb 6, 2020
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
Compound key support in federation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants