Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions composition-js/src/__tests__/connectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("connect spec and join__directive", () => {
"schema
@link(url: \\"https://specs.apollo.dev/link/v1.0\\")
@link(url: \\"https://specs.apollo.dev/join/v0.5\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/connect/v0.1\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/connect/v0.2\\", for: EXECUTION)
@join__directive(graphs: [WITH_CONNECTORS], name: \\"link\\", args: {url: \\"https://specs.apollo.dev/connect/v0.1\\", import: [\\"@source\\"]})
@join__directive(graphs: [WITH_CONNECTORS], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\"}})
{
Expand Down Expand Up @@ -276,7 +276,7 @@ describe("connect spec and join__directive", () => {
"schema
@link(url: \\"https://specs.apollo.dev/link/v1.0\\")
@link(url: \\"https://specs.apollo.dev/join/v0.5\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/connect/v0.1\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/connect/v0.2\\", for: EXECUTION)
@join__directive(graphs: [WITH_CONNECTORS], name: \\"link\\", args: {url: \\"https://specs.apollo.dev/connect/v0.1\\", as: \\"http\\", import: [\\"@source\\"]})
@join__directive(graphs: [WITH_CONNECTORS], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\"}})
{
Expand Down Expand Up @@ -372,14 +372,31 @@ describe("connect spec and join__directive", () => {
url: "https://specs.apollo.dev/connect/v0.2"
import: ["@connect", "@source"]
)
@source(name: "v1", http: { baseURL: "http://v1" })
@source(
name: "v1"
http: {
baseURL: "http://v1"
path: ""
queryParams: ""
}
)

type Query {
resources: [Resource!]!
@connect(source: "v1", http: { GET: "/resources" }, selection: "")
}

type Resource @key(fields: "id") @connect(source: "v1", http: { GET: "/resources" }, batch: { maxSize: 5 } selection: "") {
type Resource @key(fields: "id")
@connect(
source: "v1"
http: {
GET: "/resources"
path: ""
queryParams: ""
}
batch: { maxSize: 5 }
selection: ""
) {
id: ID!
name: String!
}
Expand Down Expand Up @@ -422,7 +439,8 @@ describe("connect spec and join__directive", () => {
@link(url: \\"https://specs.apollo.dev/connect/v0.2\\", for: EXECUTION)
@join__directive(graphs: [WITH_CONNECTORS_V0_1_], name: \\"link\\", args: {url: \\"https://specs.apollo.dev/connect/v0.1\\", import: [\\"@connect\\", \\"@source\\"]})
@join__directive(graphs: [WITH_CONNECTORS_V0_2_], name: \\"link\\", args: {url: \\"https://specs.apollo.dev/connect/v0.2\\", import: [\\"@connect\\", \\"@source\\"]})
@join__directive(graphs: [WITH_CONNECTORS_V0_1_, WITH_CONNECTORS_V0_2_], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\"}})
@join__directive(graphs: [WITH_CONNECTORS_V0_1_], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\"}})
@join__directive(graphs: [WITH_CONNECTORS_V0_2_], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\", path: \\"\\", queryParams: \\"\\"}})
{
query: Query
}
Expand Down Expand Up @@ -492,7 +510,7 @@ describe("connect spec and join__directive", () => {

type Resource
@join__type(graph: WITH_CONNECTORS_V0_2_, key: \\"id\\")
@join__directive(graphs: [WITH_CONNECTORS_V0_2_], name: \\"connect\\", args: {source: \\"v1\\", http: {GET: \\"/resources\\"}, batch: {maxSize: 5}, selection: \\"\\"})
@join__directive(graphs: [WITH_CONNECTORS_V0_2_], name: \\"connect\\", args: {source: \\"v1\\", http: {GET: \\"/resources\\", path: \\"\\", queryParams: \\"\\"}, batch: {maxSize: 5}, selection: \\"\\"})
{
id: ID!
name: String!
Expand Down
151 changes: 107 additions & 44 deletions internals-js/src/specs/connectSpec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {DirectiveLocation, GraphQLError} from 'graphql';
import { CorePurpose, FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec";
import { DirectiveLocation, GraphQLError } from 'graphql';
import {
CorePurpose,
FeatureDefinition,
FeatureDefinitions,
FeatureUrl,
FeatureVersion,
} from './coreSpec';
import {
Schema,
NonNullType,
Expand All @@ -8,41 +14,56 @@
ListType,
} from '../definitions';
import { registerKnownFeature } from '../knownCoreFeatures';
import { createDirectiveSpecification, createScalarTypeSpecification } from '../directiveAndTypeSpecification';
import {
createDirectiveSpecification,
createScalarTypeSpecification,
} from '../directiveAndTypeSpecification';

export const connectIdentity = 'https://specs.apollo.dev/connect';

const CONNECT = "connect";
const SOURCE = "source";
const URL_PATH_TEMPLATE = "URLPathTemplate";
const JSON_SELECTION = "JSONSelection";
const CONNECT_HTTP = "ConnectHTTP";
const CONNECT_BATCH = "ConnectBatch";
const SOURCE_HTTP = "SourceHTTP";
const HTTP_HEADER_MAPPING = "HTTPHeaderMapping";
const CONNECT = 'connect';
const SOURCE = 'source';
const URL_PATH_TEMPLATE = 'URLPathTemplate';
const JSON_SELECTION = 'JSONSelection';
const CONNECT_HTTP = 'ConnectHTTP';
const CONNECT_BATCH = 'ConnectBatch';
const SOURCE_HTTP = 'SourceHTTP';
const HTTP_HEADER_MAPPING = 'HTTPHeaderMapping';

export class ConnectSpecDefinition extends FeatureDefinition {
constructor(version: FeatureVersion, readonly minimumFederationVersion: FeatureVersion) {
super(new FeatureUrl(connectIdentity, CONNECT, version), minimumFederationVersion);

this.registerDirective(createDirectiveSpecification({
name: CONNECT,
locations: [DirectiveLocation.FIELD_DEFINITION],
repeatable: true,
// We "compose" these directives using the `@join__directive` mechanism,
// so they do not need to be composed in the way passing `composes: true`
// here implies.
composes: false,
}));

this.registerDirective(createDirectiveSpecification({
name: SOURCE,
locations: [DirectiveLocation.SCHEMA],
repeatable: true,
composes: false,
}));

this.registerType(createScalarTypeSpecification({ name: URL_PATH_TEMPLATE }));
constructor(
version: FeatureVersion,
readonly minimumFederationVersion: FeatureVersion,
) {
super(
new FeatureUrl(connectIdentity, CONNECT, version),
minimumFederationVersion,
);

this.registerDirective(
createDirectiveSpecification({
name: CONNECT,
locations: [DirectiveLocation.FIELD_DEFINITION],
repeatable: true,
// We "compose" these directives using the `@join__directive` mechanism,
// so they do not need to be composed in the way passing `composes: true`
// here implies.
composes: false,
}),
);

this.registerDirective(
createDirectiveSpecification({
name: SOURCE,
locations: [DirectiveLocation.SCHEMA],
repeatable: true,
composes: false,
}),
);

this.registerType(
createScalarTypeSpecification({ name: URL_PATH_TEMPLATE }),
);
this.registerType(createScalarTypeSpecification({ name: JSON_SELECTION }));
this.registerType({ name: CONNECT_HTTP, checkOrAdd: () => [] });
this.registerType({ name: SOURCE_HTTP, checkOrAdd: () => [] });
Expand All @@ -65,7 +86,10 @@
) repeatable on FIELD_DEFINITION
| OBJECT # added in v0.2, validation enforced in rust
*/
const connect = this.addDirective(schema, CONNECT).addLocations(DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT);
const connect = this.addDirective(schema, CONNECT).addLocations(

Check warning on line 89 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L89

Added line #L89 was not covered by tests
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
);
connect.repeatable = true;

connect.addArgument(SOURCE, schema.stringType());
Expand All @@ -77,7 +101,9 @@
value: String
}
*/
const HTTPHeaderMapping = schema.addType(new InputObjectType(this.typeNameInSchema(schema, HTTP_HEADER_MAPPING)!));
const HTTPHeaderMapping = schema.addType(

Check warning on line 104 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L104

Added line #L104 was not covered by tests
new InputObjectType(this.typeNameInSchema(schema, HTTP_HEADER_MAPPING)!),
);
HTTPHeaderMapping.addField(new InputFieldDefinition('name')).type =
new NonNullType(schema.stringType());
HTTPHeaderMapping.addField(new InputFieldDefinition('from')).type =
Expand All @@ -94,17 +120,33 @@
DELETE: URLPathTemplate
body: JSONSelection
headers: [HTTPHeaderMapping!]

# added in v0.2
path: JSONSelection
query: JSONSelection
}
*/
const ConnectHTTP = schema.addType(new InputObjectType(this.typeNameInSchema(schema, CONNECT_HTTP)!));
ConnectHTTP.addField(new InputFieldDefinition('GET')).type = URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('POST')).type = URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('PUT')).type = URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('PATCH')).type = URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('DELETE')).type = URLPathTemplate;
const ConnectHTTP = schema.addType(

Check warning on line 129 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L129

Added line #L129 was not covered by tests
new InputObjectType(this.typeNameInSchema(schema, CONNECT_HTTP)!),
);
ConnectHTTP.addField(new InputFieldDefinition('GET')).type =

Check warning on line 132 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L132

Added line #L132 was not covered by tests
URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('POST')).type =

Check warning on line 134 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L134

Added line #L134 was not covered by tests
URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('PUT')).type =

Check warning on line 136 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L136

Added line #L136 was not covered by tests
URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('PATCH')).type =

Check warning on line 138 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L138

Added line #L138 was not covered by tests
URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('DELETE')).type =

Check warning on line 140 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L140

Added line #L140 was not covered by tests
URLPathTemplate;
ConnectHTTP.addField(new InputFieldDefinition('body')).type = JSONSelection;
ConnectHTTP.addField(new InputFieldDefinition('headers')).type =
new ListType(new NonNullType(HTTPHeaderMapping));

ConnectHTTP.addField(new InputFieldDefinition('path')).type = JSONSelection;
ConnectHTTP.addField(new InputFieldDefinition('queryParams')).type =

Check warning on line 147 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L146-L147

Added lines #L146 - L147 were not covered by tests
JSONSelection;

connect.addArgument('http', new NonNullType(ConnectHTTP));

const ConnectBatch = schema.addType(new InputObjectType(this.typeNameInSchema(schema, CONNECT_BATCH)!));
Expand All @@ -130,14 +172,23 @@
input SourceHTTP {
baseURL: String!
headers: [HTTPHeaderMapping!]

# added in v0.2
path: JSONSelection
query: JSONSelection
}
*/
const SourceHTTP = schema.addType(new InputObjectType(this.typeNameInSchema(schema, SOURCE_HTTP)!));
const SourceHTTP = schema.addType(

Check warning on line 181 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L181

Added line #L181 was not covered by tests
new InputObjectType(this.typeNameInSchema(schema, SOURCE_HTTP)!),
);
SourceHTTP.addField(new InputFieldDefinition('baseURL')).type =
new NonNullType(schema.stringType());
SourceHTTP.addField(new InputFieldDefinition('headers')).type =
new ListType(new NonNullType(HTTPHeaderMapping));

SourceHTTP.addField(new InputFieldDefinition('path')).type = JSONSelection;
SourceHTTP.addField(new InputFieldDefinition('queryParams')).type = JSONSelection;

Check warning on line 190 in internals-js/src/specs/connectSpec.ts

View check run for this annotation

Codecov / codecov/patch

internals-js/src/specs/connectSpec.ts#L189-L190

Added lines #L189 - L190 were not covered by tests

source.addArgument('http', new NonNullType(SourceHTTP));

return [];
Expand All @@ -148,8 +199,20 @@
}
}

export const CONNECT_VERSIONS = new FeatureDefinitions<ConnectSpecDefinition>(connectIdentity)
.add(new ConnectSpecDefinition(new FeatureVersion(0, 1), new FeatureVersion(2, 10)))
.add(new ConnectSpecDefinition(new FeatureVersion(0, 2), new FeatureVersion(2, 11)));
export const CONNECT_VERSIONS = new FeatureDefinitions<ConnectSpecDefinition>(
connectIdentity,
)
.add(
new ConnectSpecDefinition(
new FeatureVersion(0, 1),
new FeatureVersion(2, 10),
),
)
.add(
new ConnectSpecDefinition(
new FeatureVersion(0, 2),
new FeatureVersion(2, 11),
),
);

registerKnownFeature(CONNECT_VERSIONS);