-
Notifications
You must be signed in to change notification settings - Fork 88
Description
It's currently possible to issue an entities query with representations that have non-existent fields on the schema. Using an example for testing that's provided in your README:
it "resolves the blog post entities" do
blog_post = BlogPost.create!(attributes)
query = <<~GRAPHQL
query($representations: [_Any!]!) {
_entities(representations: $representations) {
... on BlogPost {
id
title
body
}
}
}
GRAPHQL
variables = { representations: [{ __typename: "BlogPost", id: blog_post.id }] }
result = Schema.execute(query, variables: variables)
expect(result.dig("data", "_entities", 0, "id")).to eq(blog_post.id)
end
The above works correctly. If you using the following representation with a bad typename:
{ representations: [{ __typename: "BlogPostDoesNotExist", id: blog_post.id }] }
You get a runtime error because the schema fails to resolve BlogPostDoesNotExist to a known type. This is good!
However, If you do this:
{ representations: [{ __typename: "BlogPost", id: blog_post.id, randomFieldThatDoesNotExist: 5 }] }
The query runs without error despite the field randomFieldThatDoesNotExist being present (undefined in the BlogPost type).
Correct me if I'm wrong, but I believe all representations for a given type K that are being issued to a subgraph must only reference a set of fields that are a subset of fields defined for K in the subgraph. So For example, if I have type BlogPost that has fields A, B, and C. All entities queries containing representations for BlogPost must, at minimum, contain the relevant key fields and any other field that's defined on BlogPost that's a subset of {A B C}.
PS: Thank you for this gem!