apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
566 stars 43 forks source link

`Schema::type_field` should work for all variants of `ExtendedType` #892

Closed tninesling closed 1 month ago

tninesling commented 1 month ago

Description

When processing operations in the demand control plugin, we traverse the ExecutableDocument and score each field based on its type and directives. Specifically, we check for directives applied to the schema. Since the router's request pipeline parses operations using the API schema instead of the supergraph schema, these directives on FieldDefinitions are stripped.

It has been suggested that we look up the supergraph schema's definitions using Schema::type_field, but this returns a NoSuchField error for scalars, unions, enums, and input objects. Instead, these variants should have the same definition lookup functionality as objects and interfaces.

Proposal

For variants of ExtendedType which do not already have it, add a field definition mapping equivalent to that on objects and interfaces: pub fields: IndexMap<Name, Component<FieldDefinition>>. Then use the new lookups inside Schema::type_field.

tninesling commented 1 month ago

The lookup failure was caused by user error. This change is no longer required

SimonSapin commented 1 month ago

For anyone finding this later: the type name given to Schema::type_field must be the type of the parent selection set (the type whose definition contains the field definition we want), not the type of the field.