Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update product subgraph test schema with additional @key test cases #165

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

dariuszkuc
Copy link
Member

Update product subgraph with additional entites to separate testing for various @key test cases. Previously we were testing single entity that was supposed to define multiple @key directives. This was problematic as not all implementations support repeatable directives and we never checked whether given @key test case was actually present in the schema (test was executing _entities query only).

Schema changes (existing fields and types are omitted for clarity):

type Product @key(fields: "id") @key(fields: "sku package") @key(fields: "sku variation { id }") {
  # new field
  research: [ProductResearch!]!
}

type DeprecatedProduct @key(fields: "sku package") {
  sku: String!
  package: String!
  reason: String
  createdBy: User
}

type ProductResearch @key(fields: "study { caseNumber }") {
  study: CaseStudy!
  outcome: String
}

type CaseStudy {
  caseNumber: ID!
  description: String
}

extend type Query {
  # new query
  deprecatedProduct(sku: String!, package: String!): DeprecatedProduct @deprecated(reason: "Use product query instead")
}

Update @key tests cases to verify:

  • single field @key functionality against User type
  • multiple field @key functionality against DeprecatedProduct type
  • composite object @key functionality against ProductResearch type
  • repeatable @key functionality against Product type (this test combines old tests into a single one)

Related Issues:

Update `product` subgraph with additional entites to separate testing for various `@key` test cases. Previously we were testing single entity that was supposed to define multiple `@key` directives. This was problematic as not all implementations support repeatable directives and we never checked whether given `@key` test case was actually present in the schema (test was executing `_entities` query only).

Schema changes (existing fields and types are omitted for clarity):

```graphql
type Product @key(fields: "id") @key(fields: "sku package") @key(fields: "sku variation { id }") {
  # new field
  research: [ProductResearch!]!
}

type DeprecatedProduct @key(fields: "sku package") {
  sku: String!
  package: String!
  reason: String
  createdBy: User
}

type ProductResearch @key(fields: "study { caseNumber }") {
  study: CaseStudy!
  outcome: String
}

type CaseStudy {
  caseNumber: ID!
  description: String
}

extend type Query {
  # new query
  deprecatedProduct(sku: String!, package: String!): DeprecatedProduct @deprecated(reason: "Use product query instead")
}
```

Update `@key` tests cases to verify:

* single field `@key` functionality against `User` type
* multiple field `@key` functionality against `DeprecatedProduct` type
* composite object `@key` functionality against `ProductResearch` type
* repeatable `@key` functionality against `Product` type (this test combines old tests into a single one)

Related Issues:

* resolves apollographql#144
* resolves apollographql#149
@dariuszkuc dariuszkuc added type: test Update federation compatibility tests type: schema change Change introduces change to the subgraph schemas labels Aug 11, 2022
@kdawgwilk
Copy link
Contributor

I like that you left the repeated @key on Product to test for repeatability of the directive 👍

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Awesome @dariuszkuc - thanks very much for tackling this! 🎉

@dariuszkuc dariuszkuc merged commit bfbedcd into apollographql:main Aug 11, 2022
@dariuszkuc dariuszkuc deleted the key_testing branch August 11, 2022 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: schema change Change introduces change to the subgraph schemas type: test Update federation compatibility tests
Projects
None yet
3 participants