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

Allow reference to field without optional arguments in @external definition #2964

Open
smyrick opened this issue Mar 20, 2024 · 1 comment
Open

Comments

@smyrick
Copy link
Member

smyrick commented Mar 20, 2024

Lets say I have this schema today which does compose ✅

  • I have one field Location.photo that accepts zero arguments today
  • I can reference that in another subgraph with @external
  • I can also request the value to the resolver with @requires

Subgraph 1

type Query {
  locations: [Location]
}

type Location @key(fields: "id") {
    id: ID!
    name: String!
    photo: String!
}

Subgraph 2

type Location @key(fields: "id") {
    id: ID!
    photo: String! @external
    banner: String @requires(fields: "photo")
}

Now lets say I want to add a new optional argument to the Location.photo field. If I make this optional or specify a default this is not a breaking change for clients and would be accepted in a monograph as valid, however with composition this now fails

Subgraph 1

type Query {
  locations: [Location]
}

type Location @key(fields: "id") {
    id: ID!
    name: String!
    photo(smallVersion: Boolean): String! # New optional arg shouldn't break existing clients
}

Subgraph 2 ❌ (fails composition)

type Location @key(fields: "id") {
    id: ID!
    photo: String! @external
    banner: String @requires(fields: "photo")
}

In order to fix this I need to go to every subgraph reference and update those as well

Subgraph 1

type Query {
  locations: [Location]
}

type Location @key(fields: "id") {
    id: ID!
    name: String!
    photo(smallVersion: Boolean): String! # New optional arg shouldn't break existing clients
}

Subgraph 2 ✅ (passes composition)

type Location @key(fields: "id") {
    id: ID!
    photo(smallVersion: Boolean): String! @external # Need to update reference here and in every subgraph (blocking composition pipeline)
    banner: String @requires(fields: "photo")
}

What I would like to happen

Instead it would be nice if composition recognized when we are only referencing fields with optional arguments and not including them will not break any operations.

Caveat

There is a bit of a work around today which I am not sure is intentional or not, but you can actually add the reference first to the @external field only and this will not break composition, then you can go and add it to the source field.

@smyrick
Copy link
Member Author

smyrick commented Mar 20, 2024

Slightly related, this came up when debugging the issues here: #2276

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant