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
1 change: 1 addition & 0 deletions internal/reports/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ type Counterpart struct {
Name string
CheckedParticipant string
Environment string
IsGraph bool
}
6 changes: 5 additions & 1 deletion internal/reports/protocols/graphql/field_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{{
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/reports/protocols/graphql/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion internal/reports/protocols/graphql/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
Expand Down
11 changes: 6 additions & 5 deletions internal/reports/protocols/graphql/violation_lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion internal/reports/verdict_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ type Review {
id: ID!
body: String!
}

type Pet @key(fields: "id") {
id: ID!
summary: String
}
3 changes: 3 additions & 0 deletions tests/e2e/fixtures/graph_from_context_unreachable/web_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ schemas:
name:
type: string
nullable: true
summary:
type: string
nullable: true
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ type Review {
id: ID!
body: String!
}

type Pet @key(fields: "id") {
id: ID!
shippingCost: Int
}
3 changes: 3 additions & 0 deletions tests/e2e/fixtures/graph_requires_unreachable/web_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ schemas:
name:
type: string
nullable: true
shippingCost:
type: integer
nullable: true
3 changes: 2 additions & 1 deletion tests/e2e/fixtures/graphql_named_type_changed/web_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ schemas:
type: object
properties:
id:
type: string
type: scalar
name: ID

MaybePet:
ref: Pet
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/fixtures/graphql_named_type_changed/web_v2.yaml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 13 additions & 13 deletions tests/e2e/graph_from_context_unreachable.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
}
24 changes: 12 additions & 12 deletions tests/e2e/graph_override_label_unreachable.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
26 changes: 13 additions & 13 deletions tests/e2e/graph_requires_unreachable.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
}
35 changes: 26 additions & 9 deletions tests/e2e/graphql_named_type_changed.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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\")"
}

Expand All @@ -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\")"
}

Expand All @@ -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"
}
Loading
Loading