Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions composition-js/src/__tests__/connectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ describe("connect spec and join__directive", () => {
path: ""
queryParams: ""
}
errors: { message: "" extensions: "" }
)

type Query {
Expand All @@ -395,6 +396,7 @@ describe("connect spec and join__directive", () => {
queryParams: ""
}
batch: { maxSize: 5 }
errors: { message: "" extensions: "" }
selection: ""
) {
id: ID!
Expand Down Expand Up @@ -440,7 +442,7 @@ describe("connect spec and join__directive", () => {
@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_], 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: \\"\\"}})
@join__directive(graphs: [WITH_CONNECTORS_V0_2_], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\", path: \\"\\", queryParams: \\"\\"}, errors: {message: \\"\\", extensions: \\"\\"}})
{
query: Query
}
Expand Down Expand Up @@ -510,7 +512,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\\", path: \\"\\", queryParams: \\"\\"}, batch: {maxSize: 5}, selection: \\"\\"})
@join__directive(graphs: [WITH_CONNECTORS_V0_2_], name: \\"connect\\", args: {source: \\"v1\\", http: {GET: \\"/resources\\", path: \\"\\", queryParams: \\"\\"}, batch: {maxSize: 5}, errors: {message: \\"\\", extensions: \\"\\"}, selection: \\"\\"})
{
id: ID!
name: String!
Expand Down
14 changes: 13 additions & 1 deletion internals-js/src/specs/connectSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const URL_PATH_TEMPLATE = 'URLPathTemplate';
const JSON_SELECTION = 'JSONSelection';
const CONNECT_HTTP = 'ConnectHTTP';
const CONNECT_BATCH = 'ConnectBatch';
const SOURCE_HTTP = 'SourceHTTP';
const CONNECT_ERRORS = "ConnectErrors";
const SOURCE_HTTP = "SourceHTTP";
const SOURCE_ERRORS = "SourceErrors";
const HTTP_HEADER_MAPPING = 'HTTPHeaderMapping';

export class ConnectSpecDefinition extends FeatureDefinition {
Expand Down Expand Up @@ -153,6 +155,11 @@ export class ConnectSpecDefinition extends FeatureDefinition {
ConnectBatch.addField(new InputFieldDefinition('maxSize')).type = schema.intType();
connect.addArgument('batch', ConnectBatch);

const ConnectErrors = schema.addType(new InputObjectType(this.typeNameInSchema(schema, CONNECT_ERRORS)!));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we make this and the source one a single ConnectorsErrors type for simplicity since they're identical? Like how we share headers.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🤔 I think the definitions should be the same. The validation in Rust is slightly different (implementation is different and variables available are different) but yea, the actual fields should be identical.

I'd have to change this in Rust too so I'll wait till you're done reviewing to actually execute this change to make sure we're still confident in it once you're done looking at both PRs 😅

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done!

ConnectErrors.addField(new InputFieldDefinition('message')).type = JSONSelection;
ConnectErrors.addField(new InputFieldDefinition('extensions')).type = JSONSelection;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I understand the design correctly, setting either message or extensions overrides the default behavior for both, right?

I would suggest that either we retain the default behavior when one is unset or we make these both required fields (here and in our better validations) so it's very clear to the user that they're turning off the default message (and getting an empty string??) if they set custom extensions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

From the design:

Configuring @source(error:) or @connect(error:) overrides default or fallback values for both message and extensions, even if extensions is not set.

I interpret that as saying that that both fields are optional... but yea, I agree that it's a bit of a confusing behaviour to have one of the fields just "disappear" if not set.

So, my rust implementation allows you to override just message or extensions (or both obviously). (see: https://github.com/apollographql/router/pull/7311/files#diff-1c93268ec072033d27937077ca358823a0569f2ac1919d2976059c7a625f1fd6)

connect.addArgument('errors', ConnectErrors);

connect.addArgument('selection', new NonNullType(JSONSelection));
connect.addArgument('entity', schema.booleanType(), false);

Expand Down Expand Up @@ -191,6 +198,11 @@ export class ConnectSpecDefinition extends FeatureDefinition {

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

const SourceErrors = schema.addType(new InputObjectType(this.typeNameInSchema(schema, SOURCE_ERRORS)!));
SourceErrors.addField(new InputFieldDefinition('message')).type = JSONSelection;
SourceErrors.addField(new InputFieldDefinition('extensions')).type = JSONSelection;
source.addArgument('errors', SourceErrors);

return [];
}

Expand Down