Skip to content

Commit

Permalink
fix: propagate ancestor exclude tags (wundergraph#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenimus authored Oct 15, 2024
1 parent f528982 commit b008d45
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composition-go/index.global.js

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion composition/src/federation/federation-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1836,14 +1836,32 @@ export class FederationFactory {
];
}

validatePathSegmentInaccessibility(path: string): boolean {
const segments = path.split(PERIOD);
if (segments.length < 1) {
return false;
}
let segment = segments[0];
for (let i = 1; i < segments.length; i++) {
if (this.inaccessiblePaths.has(segment)) {
return true;
}
segment += `.${segments[i]}`;
}
return false;
}

validateReferencesOfInaccessibleType(data: ParentDefinitionData) {
const paths = this.pathsByNamedTypeName.get(data.name);
if (!paths || paths.size < 1) {
return;
}
const invalidPaths: string[] = [];
for (const path of paths) {
if (!this.inaccessiblePaths.has(path)) {
if (this.inaccessiblePaths.has(path)) {
continue;
}
if (!this.validatePathSegmentInaccessibility(path)) {
invalidPaths.push(path);
}
}
Expand Down
131 changes: 131 additions & 0 deletions composition/tests/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,59 @@ describe('Contract tests', () => {
);
});

test('that an Argument can be removed by tag #1.1', () => {
const { errors, federationResult } = federateSubgraphsContract([subgraphA, subgraphAF], new Set<string>(['one']));
expect(errors).toBeUndefined();
expect(schemaToSortedNormalizedString(federationResult!.federatedGraphClientSchema)).toBe(
normalizeString(
schemaQueryDefinition +
`
type Object {
field: String!
}
type Query {
dummy: String!
}
`,
),
);
});

test('that an Argument can be removed by tag #1.2', () => {
const { errors, federationResult } = federateSubgraphsContract([subgraphA, subgraphAG], new Set<string>(['one']));
expect(errors).toBeUndefined();
expect(schemaToSortedNormalizedString(federationResult!.federatedGraphClientSchema)).toBe(
normalizeString(
schemaQueryDefinition +
`
type Object {
field: String!
}
type Query {
dummy: String!
}
`,
),
);
});

test('that an Argument can be removed by tag #1.3', () => {
const { errors, federationResult } = federateSubgraphsContract([subgraphA, subgraphAH], new Set<string>(['one']));
expect(errors).toBeUndefined();
expect(schemaToSortedNormalizedString(federationResult!.federatedGraphClientSchema)).toBe(
normalizeString(
schemaQueryDefinition +
`
type Query {
dummy: String!
}
`,
),
);
});

test('that a scalar is removed by tag', () => {
const { errors, federationResult } = federateSubgraphsContract([subgraphQ, subgraphR], new Set<string>(['one']));
expect(errors).toBeUndefined();
Expand Down Expand Up @@ -346,6 +399,21 @@ describe('Contract tests', () => {
);
});

test('that a nested Field can be removed by tag', () => {
const { errors, federationResult } = federateSubgraphsContract([subgraphA, subgraphAI], new Set<string>(['one']));
expect(errors).toBeUndefined();
expect(schemaToSortedNormalizedString(federationResult!.federatedGraphClientSchema)).toBe(
normalizeString(
schemaQueryDefinition +
`
type Query {
dummy: String!
}
`,
),
);
});

test('that a client schema is produced if a @tag directive is defined on an object #1.1', () => {
const { errors, federationResult } = federateSubgraphs([subgraphB, subgraphC]);
expect(errors).toBeUndefined();
Expand Down Expand Up @@ -2159,3 +2227,66 @@ const subgraphAE: Subgraph = {
}
`),
};

const subgraphAF: Subgraph = {
name: 'subgraph-af',
url: '',
definitions: parse(`
type Object {
field(input: Input @tag(name: "one")): String!
}
input Input {
name: String @tag(name: "one")
}
`),
};

const subgraphAG: Subgraph = {
name: 'subgraph-ag',
url: '',
definitions: parse(`
type Object {
field(input: [Input] @tag(name: "one")): String!
}
input Input {
name: String @tag(name: "one")
}
`),
};

const subgraphAH: Subgraph = {
name: 'subgraph-ah',
url: '',
definitions: parse(`
type Object {
field(input: [Input] = [] @tag(name: "one")): String! @tag(name: "one")
}
input Input {
name: String @tag(name: "one")
}
`),
};

const subgraphAI: Subgraph = {
name: 'subgraph-ai',
url: '',
definitions: parse(`
type Object @tag(name: "one") {
edges: [NestedObjectOne!]!
nodes: [NestedObjectTwo!]!
}
type NestedObjectOne @tag(name: "one") {
nested: NestedObjectTwo!
}
type NestedObjectTwo @tag(name: "one") {
enum: Enum!
}
enum Enum @tag(name: "one") {
A
}
`),
};
1 change: 0 additions & 1 deletion router/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ execution_config:
_, err := LoadConfig(f, "")
var js *jsonschema.ValidationError
require.ErrorAs(t, err, &js)
require.Equal(t, js.Causes[0].Error(), "at '/execution_config': oneOf failed, none matched\n- at '/execution_config': additional properties 'storage' not allowed\n- at '/execution_config': additional properties 'file' not allowed\n- at '/execution_config': additional properties 'file', 'storage' not allowed")
require.True(t,
js.Causes[0].Error() == "at '/execution_config': oneOf failed, none matched\n- at '/execution_config': additional properties 'storage' not allowed\n- at '/execution_config': additional properties 'file' not allowed\n- at '/execution_config': additional properties 'file', 'storage' not allowed" || js.Causes[0].Error() == "at '/execution_config': oneOf failed, none matched\n- at '/execution_config': additional properties 'storage' not allowed\n- at '/execution_config': additional properties 'file' not allowed\n- at '/execution_config': additional properties 'storage', 'file' not allowed",
)
Expand Down

0 comments on commit b008d45

Please sign in to comment.