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

composeAndValidate() unexpectedly generates invalid GraphQL when using @tag/@inaccessible #867

Closed
sachindshinde opened this issue Jul 9, 2021 · 0 comments · Fixed by #880
Assignees
Labels

Comments

@sachindshinde
Copy link
Contributor

composeAndValidate() in @apollo/federation@0.26.0 currently generates a supergraph schema that is invalid GraphQL when given the following subgraph schemas:

  • inventory.graphql
    extend type Product @key(fields: "id") {
      id: ID! @external @tag(name: "hi from inventory")
      dimensions: ProductDimension @external
      delivery(zip: String): DeliveryEstimates @requires(fields: "dimensions { size weight }")
    }
    type ProductDimension {
      size: String
      weight: Float @inaccessible
    }
    type DeliveryEstimates {
      estimatedDelivery: String
      fastestDelivery: String
    }
  • users.graphl
    type User @key(fields:"email") {
        email:ID!
        name: String
        totalProductsCreated: Int
    }
  • products.graphl
    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")
    }
    type ProductVariation {
      id: ID!
    }
    enum Color {
      BLUE
      GREEN
    }
    type ProductDimension {
      size: String
      weight: Float
    }
    extend type Query {
      allProducts: [Product]
      product(id: ID!): Product
    }
    extend type User @key(fields: "email") {
      email: ID! @external
      totalProductsCreated: Int @external
    }

The supergraph schema generated is specifically:

schema
  @core(feature: "https://specs.apollo.dev/core/v0.1"),
  @core(feature: "https://specs.apollo.dev/join/v0.1"),
  @core(feature: "https://specs.apollo.dev/inaccessible/v0.1")
{
  query: Query
}
directive @core(feature: String!) repeatable on SCHEMA
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet) on FIELD_DEFINITION
directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on OBJECT | INTERFACE
directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @inaccessible on FIELD_DEFINITION
enum Color {
  BLUE
  GREEN
}
type DeliveryEstimates {
  estimatedDelivery: String
  fastestDelivery: String
}
scalar join__FieldSet
enum join__Graph {
  INVENTORY @join__graph(name: "inventory" url: "http://inventory:4000/graphql")
  PRODUCTS @join__graph(name: "products" url: "http://product:4000/graphql")
  USERS @join__graph(name: "users" url: "http://users:4000/graphql")
}
type Product
  @join__owner(graph: PRODUCTS)
  @join__type(graph: PRODUCTS, key: "id")
  @join__type(graph: PRODUCTS, key: "sku package")
  @join__type(graph: PRODUCTS, key: "sku variation{id}")
  @join__type(graph: INVENTORY, key: "id")
{
  createdBy: User @join__field(graph: PRODUCTS, provides: "totalProductsCreated")
  delivery(zip: String): DeliveryEstimates @join__field(graph: INVENTORY, requires: "dimensions{size weight}")
  dimensions: ProductDimension @join__field(graph: PRODUCTS)
  id: ID! @join__field(graph: PRODUCTS) @tag(name: "hi from inventory")
  package: String @join__field(graph: PRODUCTS)
  sku: String @join__field(graph: PRODUCTS)
  variation: ProductVariation @join__field(graph: PRODUCTS)
}
type ProductDimension {
  size: String
  weight: Float @inaccessible
}
type ProductVariation {
  id: ID!
}
type Query {
  allProducts: [Product] @join__field(graph: PRODUCTS)
  product(id: ID!): Product @join__field(graph: PRODUCTS)
}
type User
  @join__owner(graph: USERS)
  @join__type(graph: USERS, key: "email")
  @join__type(graph: PRODUCTS, key: "email")
{
  email: ID! @join__field(graph: USERS)
  name: String @join__field(graph: USERS)
  totalProductsCreated: Int @join__field(graph: USERS)
}

Which notably doesn’t have a @tag directive definition, but does have usages of @tag. (So I’m guessing this is a bug with #859 .)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment