Skip to content

Commit

Permalink
Merge pull request #1652 from sachindshinde/fed2/tag-v0.2-updates
Browse files Browse the repository at this point in the history
Add support for tag v0.2
  • Loading branch information
sachindshinde authored Mar 29, 2022
2 parents 6c3b7fa + dff6b55 commit 3a7d833
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 86 deletions.
5 changes: 5 additions & 0 deletions composition-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/federation-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

## vNEXT

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- Adds Support for `@tag/v0.2`, which allows the `@tag` directive to be additionally placed on arguments, scalars, enums, enum values, input objects, and input object fields. [PR #1652](https://github.com/apollographql/federation/pull/1652).

## v2.0.0-preview.8

NOTE: Be sure to upgrade the gateway _before_ re-composing/deploying with this version. See below and the changelog for `@apollo/gateway`.
Expand Down
2 changes: 1 addition & 1 deletion composition-js/src/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ describe('composition', () => {

expect(result.errors).toBeDefined();
expect(errors(result)).toStrictEqual([
['DIRECTIVE_DEFINITION_INVALID', '[subgraphA] Found invalid @tag directive definition. Please ensure the directive definition in your schema\'s definitions matches the following:\n\tdirective @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION'],
['DIRECTIVE_DEFINITION_INVALID', '[subgraphA] Found invalid @tag directive definition. Please ensure the directive definition in your schema\'s definitions matches the following:\n\tdirective @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION'],
]);
});

Expand Down
16 changes: 11 additions & 5 deletions federation-integration-testsuite-js/src/fixtures/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ export const typeDefs = gql`
| INTERFACE
| OBJECT
| UNION
enum CacheControlScope {
PUBLIC
| ARGUMENT_DEFINITION
| SCALAR
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
enum CacheControlScope @tag(name: "from-reviews") {
PUBLIC @tag(name: "from-reviews")
PRIVATE
}
Expand All @@ -23,7 +29,7 @@ export const typeDefs = gql`
inheritMaxAge: Boolean
) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION
scalar JSON @specifiedBy(url: "https://json-spec.dev")
scalar JSON @tag(name: "from-reviews") @specifiedBy(url: "https://json-spec.dev")
schema {
query: RootQuery
Expand Down Expand Up @@ -55,7 +61,7 @@ export const typeDefs = gql`
id: ID! @tag(name: "accounts")
name: Name @cacheControl(inheritMaxAge: true)
username: String @shareable # Provided by the 'reviews' subgraph
birthDate(locale: String): String @tag(name: "admin") @tag(name: "dev")
birthDate(locale: String @tag(name: "admin")): String @tag(name: "admin") @tag(name: "dev")
account: AccountType
metadata: [UserMetadata]
ssn: String
Expand Down
18 changes: 12 additions & 6 deletions federation-integration-testsuite-js/src/fixtures/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export const typeDefs = gql`
| FIELD_DEFINITION
| OBJECT
| UNION
| ARGUMENT_DEFINITION
| SCALAR
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
type Query {
topReviews(first: Int = 5): [Review]
Expand All @@ -24,9 +30,9 @@ export const typeDefs = gql`
metadata: [MetadataOrError]
}
input UpdateReviewInput {
input UpdateReviewInput @tag(name: "from-reviews") {
id: ID!
body: String
body: String @tag(name: "from-reviews")
}
type UserMetadata {
Expand All @@ -43,7 +49,7 @@ export const typeDefs = gql`
}
interface Product @tag(name: "from-reviews") {
reviews: [Review]
reviews: [Review] @tag(name: "from-reviews")
}
type Furniture implements Product @key(fields: "upc") {
Expand Down Expand Up @@ -82,13 +88,13 @@ export const typeDefs = gql`
type Mutation {
reviewProduct(input: ReviewProduct!): Product
updateReview(review: UpdateReviewInput!): Review
updateReview(review: UpdateReviewInput! @tag(name: "from-reviews")): Review
deleteReview(id: ID!): Boolean
}
# Value type
type KeyValue @shareable {
key: String!
type KeyValue @shareable @tag(name: "from-reviews") {
key: String! @tag(name: "from-reviews")
value: String!
}
Expand Down
5 changes: 5 additions & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/gateway-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

## vNEXT

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- Adds support for `@tag/v0.2`, which allows the `@tag` directive to be additionally placed on arguments, scalars, enums, enum values, input objects, and input object fields. [PR #1652](https://github.com/apollographql/federation/pull/1652).

## v2.0.0-preview.8

NOTE: Be sure to update to this version of gateway _before_ upgrading composition. See below and the changelog for `@apollo/composition`.
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/__tests__/gateway/lifecycle-hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('lifecycle hooks', () => {
// the supergraph (even just formatting differences), this ID will change
// and this test will have to updated.
expect(secondCall[0]!.compositionId).toEqual(
'cf96012e98a17d3739f90afed59ef6a5d969d42a5780f9a069a790f2a959d711',
'2111ffa6e04caa88d5422b503f72192bfd644910fb4b56a73e0531ec79d5ea92',
);
// second call should have previous info in the second arg
expect(secondCall[1]!.compositionId).toEqual(expectedFirstId);
Expand Down
16 changes: 8 additions & 8 deletions gateway-js/src/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('core v0.1', () => {
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
enum CacheControlScope {
PRIVATE
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('core v0.1', () => {
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
enum CacheControlScope {
PRIVATE
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('core v0.2', () => {
schema
@core(feature: "https://specs.apollo.dev/core/v0.2")
@core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
@core(feature: "https://specs.apollo.dev/tag/v0.1") {
@core(feature: "https://specs.apollo.dev/tag/v0.2") {
query: Query
}
Expand All @@ -151,7 +151,7 @@ describe('core v0.2', () => {
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
enum CacheControlScope {
PRIVATE
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('core v0.2', () => {
schema
@core(feature: "https://specs.apollo.dev/core/v0.2")
@core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
@core(feature: "https://specs.apollo.dev/tag/v0.1")
@core(feature: "https://specs.apollo.dev/tag/v0.2")
@core(feature: "https://specs.apollo.dev/unsupported-feature/v0.1") {
query: Query
}
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('core v0.2', () => {
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
enum CacheControlScope {
PRIVATE
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('core v0.2', () => {
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
enum CacheControlScope {
PRIVATE
Expand Down Expand Up @@ -369,7 +369,7 @@ describe('core v0.2', () => {
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
enum CacheControlScope {
PRIVATE
Expand Down
5 changes: 3 additions & 2 deletions internals-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# CHANGELOG for `@apollo/federation-internals`

## vNext
## vNEXT

- Support for Node 17 [PR #1541](https://github.com/apollographql/federation/pull/1541).
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- Adds Support for `@tag/v0.2`, which allows the `@tag` directive to be additionally placed on arguments, scalars, enums, enum values, input objects, and input object fields. [PR #1652](https://github.com/apollographql/federation/pull/1652).

## v2.0.0-preview.8

Expand Down
4 changes: 2 additions & 2 deletions internals-js/src/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function isFieldSatisfyingInterface(field: FieldDefinition<ObjectType | Interfac
*/
function validateInterfaceRuntimeImplementationFieldsTypes(
itf: InterfaceType,
metadata: FederationMetadata,
metadata: FederationMetadata,
errorCollector: GraphQLError[],
): void {
const requiresDirective = federationMetadata(itf.schema())?.requiresDirective();
Expand Down Expand Up @@ -630,7 +630,7 @@ export class FederationBlueprint extends SchemaBlueprint {
// Historically, federation 1 has accepted invalid schema, including some where the Query type included
// the definition of `_entities` (so `_entities(representations: [_Any!]!): [_Entity]!`) but _without_
// defining the `_Any` or `_Entity` type. So while we want to be stricter for fed2 (so this kind of
// really weird case can be fixed), we want fed2 to accept as much fed1 schema as possible.
// really weird case can be fixed), we want fed2 to accept as much fed1 schema as possible.
//
// So, to avoid this problem, we ignore the _entities and _service fields if we parse them from
// a fed1 input schema. Those will be added back anyway (along with the proper types) post-parsing.
Expand Down
4 changes: 2 additions & 2 deletions internals-js/src/federationSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "./directiveAndTypeSpecification";
import { DirectiveLocation } from "graphql";
import { assert } from "./utils";
import { tagLocations } from "./tagSpec";
import { TAG_VERSIONS } from "./tagSpec";
import { federationMetadata } from "./federation";
import { registerKnownFeature } from "./knownCoreFeatures";
import { inaccessibleLocations } from "./inaccessibleSpec";
Expand Down Expand Up @@ -63,7 +63,7 @@ export const shareableDirectiveSpec = createDirectiveSpecification({

export const tagDirectiveSpec = createDirectiveSpecification({
name:'tag',
locations: tagLocations,
locations: TAG_VERSIONS.latest().tagLocations,
repeatable: true,
argumentFct: (schema) => {
return [{ name: 'name', type: new NonNullType(schema.stringType()) }];
Expand Down
1 change: 1 addition & 0 deletions internals-js/src/supergraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const SUPPORTED_FEATURES = new Set([
'https://specs.apollo.dev/join/v0.1',
'https://specs.apollo.dev/join/v0.2',
'https://specs.apollo.dev/tag/v0.1',
'https://specs.apollo.dev/tag/v0.2',
'https://specs.apollo.dev/inaccessible/v0.1',
]);

Expand Down
43 changes: 30 additions & 13 deletions internals-js/src/tagSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@ import { sameType } from "./types";

export const tagIdentity = 'https://specs.apollo.dev/tag';

export const tagLocations = [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.UNION,
];

const printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION';

export class TagSpecDefinition extends FeatureDefinition {
public readonly tagLocations: DirectiveLocation[];
private readonly printedTagDefinition: string;

constructor(version: FeatureVersion) {
super(new FeatureUrl(tagIdentity, 'tag', version));
this.tagLocations = [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.UNION,
];
this.printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION';
if (!this.isV01()) {
this.tagLocations.push(
DirectiveLocation.ARGUMENT_DEFINITION,
DirectiveLocation.SCALAR,
DirectiveLocation.ENUM,
DirectiveLocation.ENUM_VALUE,
DirectiveLocation.INPUT_OBJECT,
DirectiveLocation.INPUT_FIELD_DEFINITION,
);
this.printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION';
}
}

private isV01() {
return this.version.equals(new FeatureVersion(0, 1));
}

addElementsToSchema(schema: Schema) {
const directive = this.addDirective(schema, 'tag').addLocations(...tagLocations);
const directive = this.addDirective(schema, 'tag').addLocations(...this.tagLocations);
directive.repeatable = true;
directive.addArgument("name", new NonNullType(schema.stringType()));
}
Expand All @@ -35,10 +51,10 @@ export class TagSpecDefinition extends FeatureDefinition {
const hasUnknownArguments = Object.keys(definition.arguments()).length > 1;
const nameArg = definition.argument('name');
const hasValidNameArg = nameArg && sameType(nameArg.type!, new NonNullType(definition.schema().stringType()));
const hasValidLocations = definition.locations.every(loc => tagLocations.includes(loc));
const hasValidLocations = definition.locations.every(loc => this.tagLocations.includes(loc));
if (hasUnknownArguments || !hasValidNameArg || !hasValidLocations) {
return ERRORS.DIRECTIVE_DEFINITION_INVALID.err({
message: `Found invalid @tag directive definition. Please ensure the directive definition in your schema's definitions matches the following:\n\t${printedTagDefinition}`,
message: `Found invalid @tag directive definition. Please ensure the directive definition in your schema's definitions matches the following:\n\t${this.printedTagDefinition}`,
}
);
}
Expand All @@ -51,6 +67,7 @@ export class TagSpecDefinition extends FeatureDefinition {
}

export const TAG_VERSIONS = new FeatureDefinitions<TagSpecDefinition>(tagIdentity)
.add(new TagSpecDefinition(new FeatureVersion(0, 1)));
.add(new TagSpecDefinition(new FeatureVersion(0, 1)))
.add(new TagSpecDefinition(new FeatureVersion(0, 2)));

registerKnownFeature(TAG_VERSIONS);
5 changes: 3 additions & 2 deletions query-planner-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/query-planner-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

## vNext
## vNEXT

- Support for Node 17 [PR #1541](https://github.com/apollographql/federation/pull/1541).
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- Adds Support for `@tag/v0.2`, which allows the `@tag` directive to be additionally placed on arguments, scalars, enums, enum values, input objects, and input object fields. [PR #1652](https://github.com/apollographql/federation/pull/1652).

## v2.0.0-preview.8

Expand Down
5 changes: 3 additions & 2 deletions subgraph-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/subgraph-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

## vNext
## vNEXT

- Support for Node 17 [PR #1541](https://github.com/apollographql/federation/pull/1541).
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- Adds Support for `@tag/v0.2`, which allows the `@tag` directive to be additionally placed on arguments, scalars, enums, enum values, input objects, and input object fields. [PR #1652](https://github.com/apollographql/federation/pull/1652).

## v2.0.0-preview.8

Expand Down
Loading

0 comments on commit 3a7d833

Please sign in to comment.