-
Notifications
You must be signed in to change notification settings - Fork 237
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
feat: @requires directive on different services as gateway #470
feat: @requires directive on different services as gateway #470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments but overall LGTM. Good stuff!
if (!selectedFields.includes(field.name.value)) { | ||
continue | ||
} | ||
const directive = field.directives.find(d => d.name.value === 'requires') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be null for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm writing a test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't find a case. help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the logic, any non-external field defined on the external type and containing a directive that isn't requires
should get you the test case.
For example:
Schema:
directive @custom on OBJECT | FIELD_DEFINITION
type Size @key(fields: "id") {
id: Int!
cpus: Int!
memory: Int!
}
type Region @key(fields: "id") {
id: Int!
city: String!
}
type Metadata @key(fields: "id") {
id: Int!
description: String!
}
extend type Host @key(fields: "id") {
id: Int! @external
size: Int! @external
region: Int! @external
# Field defined here with directive that isn't `requires`
metadata: Metadata! @custom
sizeData: Size! @requires(fields: "size")
regionData: Region! @requires(fields: "region")
}
Query:
query {
hosts {
name
sizeData {
cpus
}
metadata {
description
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many thanks @jonnydgreen !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation looks good to me. Waiting for @PabloSzx @PacoDu @jonnydgreen to take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, nothing more to add than what's already been said!
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
…lo/mercurius into feat/directive-requires
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
tho I do not understand why the windows test CI does not reach 100% coverage but the linux one does
ERROR: Coverage for lines (98.88%) does not meet global threshold (100%)
ERROR: Coverage for functions (99.19%) does not meet global threshold (100%)
ERROR: Coverage for branches (98.82%) does not meet global threshold (100%)
ERROR: Coverage for statements (98.91%) does not meet global threshold (100%)
--------------------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------------------|---------|----------|---------|---------|-------------------
All files | 98.91 | 98.82 | 99.19 | 98.88 |
mercurius | 99.65 | 98.51 | 100 | 99.65 |
index.js | 99.65 | 98.51 | 100 | 99.65 | 197
mercurius/lib | 99.41 | 99.28 | 98.88 | 99.39 |
errors.js | 100 | 100 | 100 | 100 |
federation.js | 100 | 100 | 100 | 100 |
gateway.js | 96.38 | 96.61 | 92.59 | 96.24 | 357,364,367-369
handlers.js | 100 | 100 | 100 | 100 |
hooks.js | 100 | 97.73 | 100 | 100 | 52
persistedQueryDefaults.js | 100 | 100 | 100 | 100 |
queryDepth.js | 100 | 100 | 100 | 100 |
routes.js | 100 | 100 | 100 | 100 |
subscriber.js | 100 | 100 | 100 | 100 |
subscription-client.js | 100 | 100 | 100 | 100 |
subscription-connection.js | 100 | 100 | 100 | 100 |
subscription-protocol.js | 100 | 100 | 100 | 100 |
subscription.js | 100 | 100 | 100 | 100 |
symbols.js | 100 | 100 | 100 | 100 |
util.js | 100 | 100 | 100 | 100 |
mercurius/lib/federation | 100 | 100 | 100 | 100 |
compositionRules.js | 100 | 100 | 100 | 100 |
mercurius/lib/gateway | 96.77 | 97.9 | 100 | 96.61 |
make-resolver.js | 100 | 100 | 100 | 100 |
request.js | 100 | 100 | 100 | 100 |
service-map.js | 90.91 | 91.18 | 100 | 90.91 | 92-97,141-147
mercurius/tap-snapshots/test | 100 | 100 | 100 | 100 |
errors.js.test.cjs | 100 | 100 | 100 | 100 |
federation.js.test.cjs | 100 | 100 | 100 | 100 |
reply-decorator.js.test.cjs | 100 | 100 | 100 | 100 |
routes.js.test.cjs | 100 | 100 | 100 | 100 |
mercurius/tap-snapshots/test/gateway | 100 | 100 | 100 | 100 |
remote-services.js.test.cjs | 100 | 100 | 100 | 100 |
--------------------------------------|---------|----------|---------|---------|-------------------
the gateway schema poll interval is failing periodically 😞 I've been re-runing the actions for them to pass |
@PabloSzx we should really refactor those tests. Maybe open a an issue or a PR? |
Happy to help out with this if you need as the |
go for it Jonny! |
Following #456, it provide support for
@requires
directive to work properly on gateway on different servicesUsing benchmarks from https://github.com/mercurius-js/auth/tree/main/bench
this branch
master branch