From 7cc922137a6a91b5c778d94e44dd898711c6e475 Mon Sep 17 00:00:00 2001 From: alefcastelo Date: Mon, 30 Nov 2026 21:18:52 -0600 Subject: [PATCH 1/2] Run the e2e on broker 0.6.0 Co-Authored-By: Claude Opus 5.5 --- tests/e2e/compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/compose.yaml b/tests/e2e/compose.yaml index 1e4279b..502b06c 100644 --- a/tests/e2e/compose.yaml +++ b/tests/e2e/compose.yaml @@ -14,7 +14,7 @@ services: retries: 15 broker: - image: ghcr.io/bidirekt/broker:0.5.0 + image: ghcr.io/bidirekt/broker:0.6.0 environment: BIDIREKT_DATABASE_URL: postgres://broker:broker@postgres:5432/broker?sslmode=disable BIDIREKT_PUBLIC_URL: http://localhost:8080 From 39db89beb06381cd37f517929682fa34d2a59899 Mon Sep 17 00:00:00 2001 From: alefcastelo Date: Mon, 30 Nov 2026 21:37:21 -0600 Subject: [PATCH 2/2] Bring GraphQL messages and e2e in line with broker 0.6.0 - drop the graph.required_by_federation message: a federated SDL without a graph now publishes - "__typename" may be an enum or a string (schema.typename_not_string_or_enum) - explain "arguments" naming a schema with a GraphQL type "name" - "name" works on scalar, object and enum schemas - a field break through a graph links the deployed graph, which lists the fields left out of it - e2e: unreachable @requires/@fromContext/@override fields now break only the consumer that reads them; the named-type scenario declares the ID it sends Co-Authored-By: Claude Opus 5.5 --- internal/reports/protocol.go | 1 + .../reports/protocols/graphql/field_blocks.go | 6 +++- .../reports/protocols/graphql/operations.go | 1 + internal/reports/protocols/graphql/plugin.go | 5 ++- .../protocols/graphql/violation_lines.go | 11 +++--- internal/reports/verdict_report.go | 2 +- .../reviews_v1.graphqls | 5 +++ .../web_v1.yaml | 3 ++ .../reviews_v1.graphqls | 5 +++ .../graph_requires_unreachable/web_v1.yaml | 3 ++ .../graphql_named_type_changed/web_v1.yaml | 3 +- .../graphql_named_type_changed/web_v2.yaml | 24 +++++++++++++ tests/e2e/graph_from_context_unreachable.bats | 26 +++++++------- .../e2e/graph_override_label_unreachable.bats | 24 ++++++------- tests/e2e/graph_requires_unreachable.bats | 26 +++++++------- tests/e2e/graphql_named_type_changed.bats | 35 ++++++++++++++----- .../reports/protocols/graphql/plugin_test.go | 35 +++++++++++++++++++ .../protocols/graphql/violation_lines_test.go | 33 +++++++++-------- 18 files changed, 175 insertions(+), 73 deletions(-) create mode 100644 tests/e2e/fixtures/graphql_named_type_changed/web_v2.yaml diff --git a/internal/reports/protocol.go b/internal/reports/protocol.go index fe5851b..e20bba5 100644 --- a/internal/reports/protocol.go +++ b/internal/reports/protocol.go @@ -17,4 +17,5 @@ type Counterpart struct { Name string CheckedParticipant string Environment string + IsGraph bool } diff --git a/internal/reports/protocols/graphql/field_blocks.go b/internal/reports/protocols/graphql/field_blocks.go index 396b2c5..577cc0f 100644 --- a/internal/reports/protocols/graphql/field_blocks.go +++ b/internal/reports/protocols/graphql/field_blocks.go @@ -56,7 +56,7 @@ func toFieldBlock(checked checkedOperation, interaction string, contractBreak re member: details["member"], direction: direction, role: contractBreak.Role, - graph: details["graph"], + graph: cmp.Or(details["graph"], checked.graph), propertyBreakLine: line, }, places: []breakPlace{{ @@ -145,6 +145,10 @@ func writeFieldBlock(report *strings.Builder, counterpart string, block fieldBlo } report.WriteString("\n") } + + if block.graph != "" { + fmt.Fprintf(report, " %s\n", deployedGraphLink(block.graph)) + } } type propertyBreakLine struct { diff --git a/internal/reports/protocols/graphql/operations.go b/internal/reports/protocols/graphql/operations.go index e66994e..b4a67f2 100644 --- a/internal/reports/protocols/graphql/operations.go +++ b/internal/reports/protocols/graphql/operations.go @@ -13,6 +13,7 @@ type checkedOperation struct { environment string operation string sendsIt bool + graph string } // splitFieldBlocks keeps apart the breaks that are not about a field, in interaction order: the broker puts the diff --git a/internal/reports/protocols/graphql/plugin.go b/internal/reports/protocols/graphql/plugin.go index 849b55f..42606cd 100644 --- a/internal/reports/protocols/graphql/plugin.go +++ b/internal/reports/protocols/graphql/plugin.go @@ -27,7 +27,7 @@ func (this Plugin) ReportKey() string { } func (this Plugin) SchemaKeys() map[string][]string { - return map[string][]string{"name": {`"type: scalar" (GraphQL contracts only)`}} + return map[string][]string{"name": {`"type: scalar", "type: object" or "type: enum" (GraphQL contracts only)`}} } func (this Plugin) WriteTree(report *strings.Builder, counterpart reports.Counterpart, tree json.RawMessage) error { @@ -45,6 +45,9 @@ func (this Plugin) WriteTree(report *strings.Builder, counterpart reports.Counte environment: counterpart.Environment, operation: operationType + " " + field, } + if counterpart.IsGraph { + checked.graph = counterpart.Name + } fieldBlocks, resourceBreaks := splitFieldBlocks(checked, operations[operationType][field]) blocks = append(blocks, fieldBlocks...) diff --git a/internal/reports/protocols/graphql/violation_lines.go b/internal/reports/protocols/graphql/violation_lines.go index 0527646..2c5970b 100644 --- a/internal/reports/protocols/graphql/violation_lines.go +++ b/internal/reports/protocols/graphql/violation_lines.go @@ -24,21 +24,22 @@ func (this Plugin) ViolationLine(violation reports.Violation) (headline, explana return fmt.Sprintf(`"arguments" must name an object schema%s: %s is %s`, argumentsAt, details["schema"], details["type"]), "", true case "nullable": return fmt.Sprintf(`"arguments" must name a non-nullable schema%s: %s is nullable`, argumentsAt, details["schema"]), "", true + case "named": + return fmt.Sprintf(`"arguments" must name a schema without "name"%s: %s names the GraphQL type %s`, argumentsAt, details["schema"], details["name"]), + `a field's arguments are not a GraphQL type: remove its "name"`, true } return "", "", false case "schema.typename_not_allowed": return `"__typename" is only allowed in GraphQL contracts` + reports.At(reports.Location(violation.Path, "properties;__typename")), "", true - case "schema.typename_not_enum": - return fmt.Sprintf(`"__typename" must be an enum schema%s: it is %s`, reports.At(reports.Location(violation.Path, "properties;__typename")), details["type"]), - `list the type names it reads in "members"`, true + case "schema.typename_not_string_or_enum": + return fmt.Sprintf(`"__typename" must be an enum or a string schema%s: it is %s`, reports.At(reports.Location(violation.Path, "properties;__typename")), details["type"]), + `list the type names it reads in an enum's "members", or read any type name as a string`, true case "schema.scalar_without_name": return "scalar schema without name" + pathAt, "", true case "returns.required": return `missing "returns"` + pathAt, "", true case "graph.without_schema": return fmt.Sprintf("graph %q without a GraphQL schema%s", details["graph"], graphAt), "pass its " + schemaFileExtensionsText() + " in the same command", true - case "graph.required_by_federation": - return "the GraphQL schema links Apollo Federation, but no graph is declared" + pathAt, "declare it in provides.graphql.graph", true case "graph.name_taken": return fmt.Sprintf("graph name %q is already a participant name%s", details["graph"], graphAt), "pick another graph name", true case "graph.name_syntax": diff --git a/internal/reports/verdict_report.go b/internal/reports/verdict_report.go index 2232a67..71f2c15 100644 --- a/internal/reports/verdict_report.go +++ b/internal/reports/verdict_report.go @@ -80,7 +80,7 @@ func FormatNotDeployableReport(brush paint.Brush, checkedSideLabel, participant, report.WriteString("\n" + counterpartHeader(name, participant, result) + ":\n") - counterpart := Counterpart{Name: name, CheckedParticipant: participant, Environment: environment} + counterpart := Counterpart{Name: name, CheckedParticipant: participant, Environment: environment, IsGraph: len(result.Members) > 0} if err := writeTrees(&report, counterpart, result.Trees, modules); err != nil { return "", err } diff --git a/tests/e2e/fixtures/graph_from_context_unreachable/reviews_v1.graphqls b/tests/e2e/fixtures/graph_from_context_unreachable/reviews_v1.graphqls index 6853618..4724982 100644 --- a/tests/e2e/fixtures/graph_from_context_unreachable/reviews_v1.graphqls +++ b/tests/e2e/fixtures/graph_from_context_unreachable/reviews_v1.graphqls @@ -8,3 +8,8 @@ type Review { id: ID! body: String! } + +type Pet @key(fields: "id") { + id: ID! + summary: String +} diff --git a/tests/e2e/fixtures/graph_from_context_unreachable/web_v1.yaml b/tests/e2e/fixtures/graph_from_context_unreachable/web_v1.yaml index caf6e39..6533099 100644 --- a/tests/e2e/fixtures/graph_from_context_unreachable/web_v1.yaml +++ b/tests/e2e/fixtures/graph_from_context_unreachable/web_v1.yaml @@ -23,3 +23,6 @@ schemas: name: type: string nullable: true + summary: + type: string + nullable: true diff --git a/tests/e2e/fixtures/graph_requires_unreachable/reviews_v1.graphqls b/tests/e2e/fixtures/graph_requires_unreachable/reviews_v1.graphqls index 6853618..f241695 100644 --- a/tests/e2e/fixtures/graph_requires_unreachable/reviews_v1.graphqls +++ b/tests/e2e/fixtures/graph_requires_unreachable/reviews_v1.graphqls @@ -8,3 +8,8 @@ type Review { id: ID! body: String! } + +type Pet @key(fields: "id") { + id: ID! + shippingCost: Int +} diff --git a/tests/e2e/fixtures/graph_requires_unreachable/web_v1.yaml b/tests/e2e/fixtures/graph_requires_unreachable/web_v1.yaml index caf6e39..9e2b6a1 100644 --- a/tests/e2e/fixtures/graph_requires_unreachable/web_v1.yaml +++ b/tests/e2e/fixtures/graph_requires_unreachable/web_v1.yaml @@ -23,3 +23,6 @@ schemas: name: type: string nullable: true + shippingCost: + type: integer + nullable: true diff --git a/tests/e2e/fixtures/graphql_named_type_changed/web_v1.yaml b/tests/e2e/fixtures/graphql_named_type_changed/web_v1.yaml index ddf8a67..aa5aff2 100644 --- a/tests/e2e/fixtures/graphql_named_type_changed/web_v1.yaml +++ b/tests/e2e/fixtures/graphql_named_type_changed/web_v1.yaml @@ -11,7 +11,8 @@ schemas: type: object properties: id: - type: string + type: scalar + name: ID MaybePet: ref: Pet diff --git a/tests/e2e/fixtures/graphql_named_type_changed/web_v2.yaml b/tests/e2e/fixtures/graphql_named_type_changed/web_v2.yaml new file mode 100644 index 0000000..ddf8a67 --- /dev/null +++ b/tests/e2e/fixtures/graphql_named_type_changed/web_v2.yaml @@ -0,0 +1,24 @@ +consumes: + ${API}: + graphql: + query: + pet: + arguments: PetArgs + returns: MaybePet + +schemas: + PetArgs: + type: object + properties: + id: + type: string + + MaybePet: + ref: Pet + nullable: true + + Pet: + type: object + properties: + name: + type: string diff --git a/tests/e2e/graph_from_context_unreachable.bats b/tests/e2e/graph_from_context_unreachable.bats index f3e221e..c35891b 100644 --- a/tests/e2e/graph_from_context_unreachable.bats +++ b/tests/e2e/graph_from_context_unreachable.bats @@ -69,7 +69,7 @@ setup() { assert_success } -@test "publish petstore_web v1 (reads Pet.name through the graph)" { +@test "publish petstore_web v1 (reads Pet.name and Pet.summary through the graph)" { run bidirekt publish ./web_v1.yaml --participant "$WEB" --version v1 assert_success } @@ -89,28 +89,28 @@ setup() { assert_success } -@test "petstore_reviews v2 blocked: query pet reaches Pet.summary without the context its argument reads" { +@test "petstore_reviews v2 blocked: query pet never sets the context an argument of Pet.summary reads, so it loses Pet.summary" { run bidirekt can-i-deploy "$REVIEWS" --version v2 --environment "$PRODUCTION" assert_failure assert_output --partial "$REVIEWS v2 cannot be deployed to $PRODUCTION $WEB (v1, deployed): - query pet - - $REVIEWS (via $GRAPH) makes $GRAPH fail to compose in $PRODUCTION, and $WEB calls query pet - query pet.summary can't be resolved: $REVIEWS v2 fills an argument of Pet.summary from the context review, which no type above it in the query sets - → $REVIEWS: make $GRAPH compose - deployed graph: /graphs/$GRAPH" + Pet.summary — $REVIEWS (via $GRAPH) doesn't provide it, but $WEB reads it + → $REVIEWS: provide it + → $WEB: stop reading it there + · query pet returns at \"\$.summary\" + deployed graph: /graphs/$GRAPH" } -@test "validate the petstore_reviews v2 files: the same refusal, naming the local candidate" { +@test "validate the petstore_reviews v2 files: the same break" { run bidirekt validate ./graph.yaml ./reviews_v2.graphqls --participant "$REVIEWS" --environment "$PRODUCTION" assert_failure assert_output --partial "$REVIEWS local contract cannot be deployed to $PRODUCTION $WEB (v1, deployed): - query pet - - $REVIEWS (via $GRAPH) makes $GRAPH fail to compose in $PRODUCTION, and $WEB calls query pet - query pet.summary can't be resolved: $REVIEWS (local candidate) fills an argument of Pet.summary from the context review, which no type above it in the query sets - → $REVIEWS: make $GRAPH compose - deployed graph: /graphs/$GRAPH" + Pet.summary — $REVIEWS (via $GRAPH) doesn't provide it, but $WEB reads it + → $REVIEWS: provide it + → $WEB: stop reading it there + · query pet returns at \"\$.summary\" + deployed graph: /graphs/$GRAPH" } diff --git a/tests/e2e/graph_override_label_unreachable.bats b/tests/e2e/graph_override_label_unreachable.bats index 6710036..5f6a5b7 100644 --- a/tests/e2e/graph_override_label_unreachable.bats +++ b/tests/e2e/graph_override_label_unreachable.bats @@ -89,28 +89,28 @@ setup() { assert_success } -@test "petstore_reviews v2 blocked: petstore_api can't reach the Pet.name petstore_reviews serves during the migration" { +@test "petstore_reviews v2 blocked: petstore_api can't reach the Pet.name petstore_reviews serves during the migration, so query pet loses it" { run bidirekt can-i-deploy "$REVIEWS" --version v2 --environment "$PRODUCTION" assert_failure assert_output --partial "$REVIEWS v2 cannot be deployed to $PRODUCTION $WEB (v1, deployed): - query pet - - $REVIEWS (via $GRAPH) makes $GRAPH fail to compose in $PRODUCTION, and $WEB calls query pet - query pet.name can't be resolved: no resolvable @key leads from $API v1 to $REVIEWS v2 on Pet - → $REVIEWS: make $GRAPH compose - deployed graph: /graphs/$GRAPH" + Pet.name — $REVIEWS (via $GRAPH) doesn't provide it, but $WEB reads it + → $REVIEWS: provide it + → $WEB: stop reading it there + · query pet returns at \"\$.name\" + deployed graph: /graphs/$GRAPH" } -@test "validate the petstore_reviews v2 files: the same refusal, naming the local candidate" { +@test "validate the petstore_reviews v2 files: the same break" { run bidirekt validate ./graph.yaml ./reviews_v2.graphqls --participant "$REVIEWS" --environment "$PRODUCTION" assert_failure assert_output --partial "$REVIEWS local contract cannot be deployed to $PRODUCTION $WEB (v1, deployed): - query pet - - $REVIEWS (via $GRAPH) makes $GRAPH fail to compose in $PRODUCTION, and $WEB calls query pet - query pet.name can't be resolved: no resolvable @key leads from $API v1 to $REVIEWS (local candidate) on Pet - → $REVIEWS: make $GRAPH compose - deployed graph: /graphs/$GRAPH" + Pet.name — $REVIEWS (via $GRAPH) doesn't provide it, but $WEB reads it + → $REVIEWS: provide it + → $WEB: stop reading it there + · query pet returns at \"\$.name\" + deployed graph: /graphs/$GRAPH" } diff --git a/tests/e2e/graph_requires_unreachable.bats b/tests/e2e/graph_requires_unreachable.bats index 1c4248f..1489bfb 100644 --- a/tests/e2e/graph_requires_unreachable.bats +++ b/tests/e2e/graph_requires_unreachable.bats @@ -69,7 +69,7 @@ setup() { assert_success } -@test "publish petstore_web v1 (reads Pet.name through the graph)" { +@test "publish petstore_web v1 (reads Pet.name and Pet.shippingCost through the graph)" { run bidirekt publish ./web_v1.yaml --participant "$WEB" --version v1 assert_success } @@ -89,28 +89,28 @@ setup() { assert_success } -@test "petstore_reviews v2 blocked: no resolvable @key reaches what the @requires selects" { +@test "petstore_reviews v2 blocked: no resolvable @key reaches what the @requires selects, so query pet loses Pet.shippingCost" { run bidirekt can-i-deploy "$REVIEWS" --version v2 --environment "$PRODUCTION" assert_failure assert_output --partial "$REVIEWS v2 cannot be deployed to $PRODUCTION $WEB (v1, deployed): - query pet - - $REVIEWS (via $GRAPH) makes $GRAPH fail to compose in $PRODUCTION, and $WEB calls query pet - query pet.shippingCost can't be resolved: no resolvable @key leads from $REVIEWS v2 to what its @requires(fields: \"weight\") selects on Pet - → $REVIEWS: make $GRAPH compose - deployed graph: /graphs/$GRAPH" + Pet.shippingCost — $REVIEWS (via $GRAPH) doesn't provide it, but $WEB reads it + → $REVIEWS: provide it + → $WEB: stop reading it there + · query pet returns at \"\$.shippingCost\" + deployed graph: /graphs/$GRAPH" } -@test "validate the petstore_reviews v2 files: the same refusal, naming the local candidate" { +@test "validate the petstore_reviews v2 files: the same break" { run bidirekt validate ./graph.yaml ./reviews_v2.graphqls --participant "$REVIEWS" --environment "$PRODUCTION" assert_failure assert_output --partial "$REVIEWS local contract cannot be deployed to $PRODUCTION $WEB (v1, deployed): - query pet - - $REVIEWS (via $GRAPH) makes $GRAPH fail to compose in $PRODUCTION, and $WEB calls query pet - query pet.shippingCost can't be resolved: no resolvable @key leads from $REVIEWS (local candidate) to what its @requires(fields: \"weight\") selects on Pet - → $REVIEWS: make $GRAPH compose - deployed graph: /graphs/$GRAPH" + Pet.shippingCost — $REVIEWS (via $GRAPH) doesn't provide it, but $WEB reads it + → $REVIEWS: provide it + → $WEB: stop reading it there + · query pet returns at \"\$.shippingCost\" + deployed graph: /graphs/$GRAPH" } diff --git a/tests/e2e/graphql_named_type_changed.bats b/tests/e2e/graphql_named_type_changed.bats index 59b25f5..e7cf472 100644 --- a/tests/e2e/graphql_named_type_changed.bats +++ b/tests/e2e/graphql_named_type_changed.bats @@ -48,7 +48,7 @@ setup() { assert_success } -@test "publish petstore_web v1" { +@test "publish petstore_web v1 (sends id as an ID)" { run bidirekt publish ./web_v1.yaml --participant "$WEB" --version v1 assert_success } @@ -74,9 +74,9 @@ setup() { assert_output --partial "$API v2 cannot be deployed to $PRODUCTION $WEB (v1, deployed): - Query.pet(id:) — $API expects it as String, but $WEB sends ID - → $API: accept ID - → $WEB: send String there + Query.pet(id:) — $API expects it as String!, but $WEB sends ID! + → $API: accept ID! + → $WEB: send String! there · query pet arguments (argument \"id\")" } @@ -86,9 +86,9 @@ $WEB (v1, deployed): assert_output --partial "$API local contract cannot be deployed to $PRODUCTION $WEB (v1, deployed): - Query.pet(id:) — $API expects it as String, but $WEB sends ID - → $API: accept ID - → $WEB: send String there + Query.pet(id:) — $API expects it as String!, but $WEB sends ID! + → $API: accept ID! + → $WEB: send String! there · query pet arguments (argument \"id\")" } @@ -97,9 +97,26 @@ $WEB (v1, deployed): assert_success } -@test "petstore_web v1 can be deployed against the deployed petstore_api v2: the consumer declares no type names" { +@test "petstore_web v1 blocked against the deployed petstore_api v2: it still sends id as an ID" { run bidirekt can-i-deploy "$WEB" --version v1 --environment "$PRODUCTION" + assert_failure + assert_output --partial "$WEB v1 cannot be deployed to $PRODUCTION + +$API (v2, deployed): + Query.pet(id:) — $WEB sends it as ID!, but $API expects String! + → $WEB: send String! + → $API: accept ID! there + · query pet arguments (argument \"id\")" +} + +@test "publish petstore_web v2 (declares no type name for id)" { + run bidirekt publish ./web_v2.yaml --participant "$WEB" --version v2 + assert_success +} + +@test "petstore_web v2 can be deployed against the deployed petstore_api v2: without a type name, a string id fits String too" { + run bidirekt can-i-deploy "$WEB" --version v2 --environment "$PRODUCTION" assert_success - assert_output --partial "$WEB v1 can be deployed to $PRODUCTION + assert_output --partial "$WEB v2 can be deployed to $PRODUCTION compared with: $API" } diff --git a/tests/reports/protocols/graphql/plugin_test.go b/tests/reports/protocols/graphql/plugin_test.go index fc2138b..a9dfe42 100644 --- a/tests/reports/protocols/graphql/plugin_test.go +++ b/tests/reports/protocols/graphql/plugin_test.go @@ -150,6 +150,40 @@ petstore_web (3.0.0, deployed): → petstore_reviews: provide it as string → petstore_web: read it as integer there · query pet returns at "$.age" + deployed graph: /graphs/petstore_graph +`, report) +} + +func TestFormatNotDeployableReportLinksTheGraphAFieldOfTheConsumerIsMissingFrom(t *testing.T) { + results := map[string]reports.CanIDeployResult{ + "petstore_graph": { + Members: map[string]string{"petstore_api": "1.4.0", "petstore_reviews": "2.0.0"}, + Trees: operationsTree(t, operations{ + "query": { + "reviews": { + "returns": { + {Reason: "property_missing_in_provider", Role: "consumer", Details: map[string]string{ + "consumerField": "Pet.name", "property": "$[].pet.name", "propertyType": "string", + "consumerName": "petstore_web", "providerName": "petstore_graph", + }}, + }, + }, + }, + }), + }, + } + + report, err := reports.FormatNotDeployableReport(paint.For(&bytes.Buffer{}), "petstore_web 3.0.0", "petstore_web", "production", results, graphqlModules) + + require.NoError(t, err) + assert.Equal(t, `petstore_web 3.0.0 cannot be deployed to production + +petstore_graph (petstore_api 1.4.0 + petstore_reviews 2.0.0, deployed): + Pet.name — petstore_web reads it, but petstore_graph doesn't provide it + → petstore_web: stop reading it + → petstore_graph: provide it + · query reviews returns at "$[].pet.name" + deployed graph: /graphs/petstore_graph `, report) } @@ -202,6 +236,7 @@ petstore_web (3.0.0, deployed): → petstore_web: read it as integer there · query pet returns at "$.age" · query pets returns at "$[].age" + deployed graph: /graphs/petstore_graph `, report) } diff --git a/tests/reports/protocols/graphql/violation_lines_test.go b/tests/reports/protocols/graphql/violation_lines_test.go index b7d7967..b02c94a 100644 --- a/tests/reports/protocols/graphql/violation_lines_test.go +++ b/tests/reports/protocols/graphql/violation_lines_test.go @@ -15,12 +15,10 @@ func TestFormatValidationFailedReportRendersTheGraphQLCodes(t *testing.T) { report := reports.FormatValidationFailedReport(paint.For(&bytes.Buffer{}), "contract validation failed", []reports.Violation{ {Code: "graph.without_schema", Path: "provides;graphql;graph", Source: "contracts/api.yaml", Details: map[string]string{"graph": "petstore_graph"}}, - {Code: "graph.required_by_federation", Source: "graph/schema.graphqls", Details: map[string]string{}}, }, modules) assert.Equal(t, `contract validation failed - contracts/api.yaml: graph "petstore_graph" without a GraphQL schema at provides graphql, pass its .graphql, .graphqls or .gql in the same command - - graph/schema.graphqls: the GraphQL schema links Apollo Federation, but no graph is declared, declare it in provides.graphql.graph `, report) } @@ -69,6 +67,13 @@ func TestFormatViolationLine(t *testing.T) { Details: map[string]string{"schema": "ReviewsArgs", "reason": "nullable"}}, headline: `"arguments" must name a non-nullable schema at schemas MaybePet properties reviews: ReviewsArgs is nullable`, }, + { + name: "schema.arguments_not_object of a consumed field naming an object with a GraphQL type name", + violation: reports.Violation{Code: "schema.arguments_not_object", Path: "consumes;petstore_api;graphql;query;pet;arguments", Source: "petstore_web.yaml", + Details: map[string]string{"schema": "PetArgs", "reason": "named", "name": "PetInput"}}, + headline: `"arguments" must name a schema without "name" at consumes petstore_api graphql query pet: PetArgs names the GraphQL type PetInput`, + explanation: `a field's arguments are not a GraphQL type: remove its "name"`, + }, { name: "schema.arguments_not_object with a reason this bidirekt doesn't know falls back to the code with its sorted details", violation: reports.Violation{Code: "schema.arguments_not_object", Path: "consumes;petstore_api;graphql;query;pet;arguments", Source: "petstore_web.yaml", @@ -82,11 +87,11 @@ func TestFormatViolationLine(t *testing.T) { headline: `"__typename" is only allowed in GraphQL contracts at schemas Pet`, }, { - name: "schema.typename_not_enum", - violation: reports.Violation{Code: "schema.typename_not_enum", Path: "schemas;Pet;properties;__typename", Source: "contracts/web.yaml", - Details: map[string]string{"type": "string"}}, - headline: `"__typename" must be an enum schema at schemas Pet: it is string`, - explanation: `list the type names it reads in "members"`, + name: "schema.typename_not_string_or_enum", + violation: reports.Violation{Code: "schema.typename_not_string_or_enum", Path: "schemas;Pet;properties;__typename", Source: "contracts/web.yaml", + Details: map[string]string{"type": "object"}}, + headline: `"__typename" must be an enum or a string schema at schemas Pet: it is object`, + explanation: `list the type names it reads in an enum's "members", or read any type name as a string`, }, { name: "schema.scalar_without_name", @@ -107,12 +112,6 @@ func TestFormatViolationLine(t *testing.T) { headline: `graph "petstore_graph" without a GraphQL schema at provides graphql`, explanation: `pass its .graphql, .graphqls or .gql in the same command`, }, - { - name: "graph.required_by_federation", - violation: reports.Violation{Code: "graph.required_by_federation", Source: "graph/schema.graphqls", Details: map[string]string{}}, - headline: `the GraphQL schema links Apollo Federation, but no graph is declared`, - explanation: `declare it in provides.graphql.graph`, - }, { name: "graph.name_taken", violation: reports.Violation{Code: "graph.name_taken", Path: "provides;graphql;graph", Source: "contracts/api.yaml", @@ -142,11 +141,11 @@ func TestFormatViolationLine(t *testing.T) { explanation: `write the field name only; arguments go in "arguments"`, }, { - name: "schema.key_not_allowed with name on an object schema points to the scalar type", + name: "schema.key_not_allowed with name on a string schema points to the types that take it", violation: reports.Violation{Code: "schema.key_not_allowed", Path: "schemas;Pet;properties;bornAt", Source: "contracts/web.yaml", - Details: map[string]string{"key": "name", "type": "object"}}, - headline: `"name" is not allowed on an object schema at schemas Pet properties bornAt`, - explanation: `use it with "type: scalar" (GraphQL contracts only)`, + Details: map[string]string{"key": "name", "type": "string"}}, + headline: `"name" is not allowed on a string schema at schemas Pet properties bornAt`, + explanation: `use it with "type: scalar", "type: object" or "type: enum" (GraphQL contracts only)`, }, } { t.Run(test.name, func(t *testing.T) {