apollographql / apollo-federation-subgraph-compatibility

A repo to test subgraph libraries compatibility with the Apollo Federation Specification
https://www.apollographql.com/docs/federation/building-supergraphs/supported-subgraphs/
MIT License
77 stars 58 forks source link

Update subgraph implementations with latest schema changes #166

Closed dariuszkuc closed 1 year ago

dariuszkuc commented 2 years ago

Issue to track which subgraph implementations should be updated due to the recent schema changes introduced for better @requires (https://github.com/apollographql/apollo-federation-subgraph-compatibility/pull/150) and @key (https://github.com/apollographql/apollo-federation-subgraph-compatibility/pull/165) tests.

Subgraph implementations:

Related issues:

dariuszkuc commented 2 years ago

Updated product schema:

extend schema
  @link(
    url: "https://specs.apollo.dev/federation/v2.0",
    import: [
      "@extends",
      "@external",
      "@key",
      "@inaccessible",
      "@override",
      "@provides",
      "@requires",
      "@shareable",
      "@tag"
    ]
  )

type Product
  @key(fields: "id")
  @key(fields: "sku package")
  @key(fields: "sku variation { id }") {
    id: ID!
    sku: String
    package: String
    variation: ProductVariation
    dimensions: ProductDimension
    createdBy: User @provides(fields: "totalProductsCreated")
    notes: String @tag(name: "internal")
    research: [ProductResearch!]!
}

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

type ProductVariation {
  id: ID!
}

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

type CaseStudy {
  caseNumber: ID!
  description: String
}

type ProductDimension @shareable {
  size: String
  weight: Float
  unit: String @inaccessible
}

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

extend type User @key(fields: "email") {
  averageProductsCreatedPerYear: Int @requires(fields: "totalProductsCreated yearsOfEmployment")
  email: ID! @external
  name: String @override(from: "users")
  totalProductsCreated: Int @external
  yearsOfEmployment: Int! @external
}

Test data:

const dimension = {
  size: "small",
  weight: 1,
  unit: "kg"
};

const user = {
  averageProductsCreatedPerYear: if (totalProductsCreated) { 
    Math.round(totalProductsCreated / yearsOfEmployment)
  } else { 
    null
  },
  email: "support@apollographql.com",
  name: "Jane Smith",
  totalProductsCreated: 1337,
  yearsOfEmployment: 10
 };

 const deprecatedProduct = {
  sku: "apollo-federation-v1",
  package: "@apollo/federation-v1",
  reason: "Migrate to Federation V2",
  createdBy: user
};

const productsResearch = [
  {
    study: {
      caseNumber: "1234",
      description: "Federation Study"
    },
    outcome: null
  },
  {
    study: {
      caseNumber: "1235",
      description: "Studio Study"
    },
    outcome: null
  },
];

const products = [
  {
    id: "apollo-federation",
    sku: "federation",
    package: "@apollo/federation",
    variation: {
      id: "OSS"
    },
    dimensions: dimension,
    research: [productsResearch[0]]
    createdBy: user,
    notes: null
  },
  {
    id: "apollo-studio",
    sku: "studio",
    package: "",
    variation: {
      id: "platform"
    },
    dimensions: dimension,
    research: [productsResearch[1]]
    createdBy: user,
    notes: null
  },
];
kdawgwilk commented 2 years ago

New test requires extend type User and doesn't allow for type User @extends for libraries that don't support the extend keyword

kdawgwilk commented 2 years ago

Also looks like the ordering of the @key directives also can cause the test to fail. e.g. My code first SDL generates

type Product @key(fields: "sku variation { id }") @key(fields: "sku package") @key(fields: "id")

but the test is looking for

type Product @key(fields: "id") @key(fields: "sku package") @key(fields: "sku variation { id }")

and so it fails even though these are syntactically equivalent

dariuszkuc commented 2 years ago

Thanks for catching those! I fixed the tests in https://github.com/apollographql/apollo-federation-subgraph-compatibility/pull/169 and https://github.com/apollographql/apollo-federation-subgraph-compatibility/pull/170 (you might need to rebase the PR).