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

First crack at adding the ability to merge core directives. #1996

Merged
merged 15 commits into from
Aug 3, 2022

Conversation

clenfest
Copy link
Contributor

Note that code is not very clean.
All skipped/todo tests are not working and will require a minor refactor

console.log etc. still exist with a few TODOs

Note that code is not very clean.
All skipped/todo tests are not working and will require a minor refactor

console.log etc. still exist with a few TODOs
@netlify
Copy link

netlify bot commented Jul 20, 2022

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit 39998fc
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/62eacdb8beab860008d742ad

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 20, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Contributor

@pcmanus pcmanus left a comment

Choose a reason for hiding this comment

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

I understand it's an unfinished patch, but left a number of early comments since I'm not sure how much I'll be able to look at future iterations.

Overall, the general approach looks good to me and it looks like a great early version :). My most important remarks are probably around turning the usages of @composeDirective we don't support into hard errors instead of just ignoring them with hints, because I worry about this creating surprises later when we do support those usages.

composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
internals-js/src/error.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
const result = composeServices([subgraphA, subgraphB]);
expect(errors(result)).toEqual([]);
expect(hints(result)).toStrictEqual([
['CORE_DIRECTIVE_MERGE_INFO', 'Composed directive "@foo" named inconsistently (subgraph, directiveName). ("subgraphA","@foo"),("subgraphB","@bar")'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Fwiw, I'd be personally ok to not even hint in that case. That is, on the one side, I get that mentioning the inconsistent naming could serve as a warning that this will get in the way if you want to compose it later. On the other side, I still worry about the value of hints diminishing if we generate too much of them, and I think the value of this one is debatable.

But if we do produce that hint, then I would suggest that:

  1. we make it a low level. At least not WARN, because there is no issue with that hint if you know what you're doing and I still think that a number of people take warnings as "call for action".
  2. I'd add more information in the message as to why raising this as a hint make sense in the first place, because that may not obvious to all users. In this case, as said above, this may be something to look at "if you ever intend to compose that directive" and this because the later currently require consistent naming.

Copy link
Contributor Author

@clenfest clenfest Jul 22, 2022

Choose a reason for hiding this comment

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

I'm assuming that this is meant to refer to the "core directive named differently in different subgraphs results in hint if not composed" test, but correct me if I'm wrong.
So get rid of the hint when neither is composed.
Hint at Warn level if one is composed
Error if both are composed.

I'm happy to get rid of this hint. I think going back to what you said initially is that really if it's not composed anywhere, it's probably just a directive that will never be composed is the right way of thinking about it.

Copy link
Contributor

@benweatherman benweatherman left a comment

Choose a reason for hiding this comment

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

🐐

Left a handful of comments, but nothing blocking. Great stuff going through a bunch of iterations on this.

composition-js/src/hints.ts Outdated Show resolved Hide resolved
composition-js/src/hints.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Show resolved Hide resolved
composition-js/src/composeDirectiveManager.ts Outdated Show resolved Hide resolved
@clenfest clenfest marked this pull request as ready for review August 3, 2022 21:18
@clenfest clenfest merged commit a3d0304 into main Aug 3, 2022
@clenfest clenfest deleted the clenfest/compose-core branch August 3, 2022 21:20
@FanfanYoung92
Copy link

FanfanYoung92 commented Sep 19, 2022

@clenfest
Hi, I used @composeDirective to preserve @dateFormat directives on supergraph. Then I saw this directive on the SupergraphSdl. But I can't find it in requestContext.schema.getDirectives() of requestDidStart Apollo plugin. Is this expected behavior? And how can I get it in apollo server plugin?
Your feedback will be highly appreciated. Thanks!
image
image

@lennyburdette
Copy link
Contributor

@FanfanYoung92 So the schema on the request context is the "API Schema", which is the schema presented to clients. It's not the "Supergraph schema" with all the metadata for query planning, or any custom directives.

You can access the supergraph schema on the Apollo Gateway instance: https://stackblitz.com/edit/basic-federation-2-fkfwme?file=gateway.js

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.

5 participants