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 products subgraph with additional entities to test out @key directive use cases #149

Closed
dariuszkuc opened this issue Aug 3, 2022 · 0 comments · Fixed by #165
Closed
Labels
type: enhancement New feature or request type: schema change Change introduces change to the subgraph schemas

Comments

@dariuszkuc
Copy link
Member

Currently products subgraph defines Product entity with multiple @key directives. Various @key use cases (single field, multiple field, composite object keys) are tested directly against the target subgraph by passing _entities query and various representations.

This testing approach is somewhat problematic as not every implementation supports repeatable directives, which means that while entity resolution logic might be fine there will be only a single @key directive present in the schema. Gateway will not be able to query the entities using other keys as they will not exist in the supergraph schema.

Proposed changes:

  • keep current Product with multiple @key directives but use it to verify single field key and repeatable directive use case
  • introduce new entity with multiple field @key
  • introduce new entity with composite object keys (i.e. field set specifies key from an object, foo { bar }) @key
@dariuszkuc dariuszkuc added type: enhancement New feature or request type: schema change Change introduces change to the subgraph schemas labels Aug 3, 2022
dariuszkuc added a commit to dariuszkuc/apollo-federation-subgraph-compatibility that referenced this issue Aug 11, 2022
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 added a commit to dariuszkuc/apollo-federation-subgraph-compatibility that referenced this issue Aug 11, 2022
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 added a commit to dariuszkuc/apollo-federation-subgraph-compatibility that referenced this issue Aug 11, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request type: schema change Change introduces change to the subgraph schemas
Projects
None yet
1 participant