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

key_fields_must_exist validation errors #53

Open
kdawgwilk opened this issue Jun 24, 2022 · 3 comments
Open

key_fields_must_exist validation errors #53

kdawgwilk opened this issue Jun 24, 2022 · 3 comments

Comments

@kdawgwilk
Copy link
Collaborator

I was working on updating the https://github.com/apollographql/apollo-federation-subgraph-compatibility elixir implementation to use more recent versions and to fix CI and I am now seeing errors with this validation phase.

== Compilation error in file lib/products_web/schema.ex ==
** (UndefinedFunctionError) function :product_variation.of_type/0 is undefined (module :product_variation is not available)
    :product_variation.of_type()
    (absinthe_federation 0.2.4) lib/absinthe/federation/schema/phase/validation/key_fields_must_exist.ex:75: Absinthe.Federation.Schema.Phase.Validation.KeyFieldsMustExist.validate_nested_key/5
    (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in Absinthe.Blueprint.Transform.prewalk/2
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:109: Absinthe.Blueprint.Transform.walk/4
    (elixir 1.13.4) lib/enum.ex:1715: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.13.4) lib/enum.ex:1715: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:139: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
    (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:15: Absinthe.Blueprint.Transform.prewalk/2
    (absinthe_federation 0.2.4) lib/absinthe/federation/schema/phase/validation/key_fields_must_exist.ex:16: Absinthe.Federation.Schema.Phase.Validation.KeyFieldsMustExist.handle_schemas/2
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in Absinthe.Blueprint.Transform.prewalk/2
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:109: Absinthe.Blueprint.Transform.walk/4
    (elixir 1.13.4) lib/enum.ex:1715: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:139: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
    (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
    (absinthe 1.7.0) lib/absinthe/blueprint/transform.ex:15: Absinthe.Blueprint.Transform.prewalk/2
    (absinthe_federation 0.2.4) lib/absinthe/federation/schema/phase/validation/key_fields_must_exist.ex:11: Absinthe.Federation.Schema.Phase.Validation.KeyFieldsMustExist.run/2

I think this may have to do with the field and field type name not being the same? the field is called variation but its type is product_variation

@kdawgwilk
Copy link
Collaborator Author

Actually this error is from this line

object = field && Absinthe.Blueprint.Schema.lookup_type(bp, field.type.of_type)

the of_type only exists if the type is non_null so this blows up for nullable fields which prompts the question can @key(fields: "...") reference nullable fields?

@kdawgwilk
Copy link
Collaborator Author

Kaden Wilkinson Jun 24th at 11:38 AM

Federation spec question: Can @key(fields: "…") reference nullable fields or do they have to be non null fields in order to be keys?

Lenny 1 day ago

the query planner can certainly send an entity reference like { __typename: "Product", id: null } to a subgraph but that might be weird for the subgraph’s entity resolver to handle

Derek 1 day ago

All the examples I've seen show them as non-nullable but I think they potentially could be nullable (as there could be multiple @keys).

Derek 1 day ago

Lenny -> would it make sense to make a guarantee from the router that the values would never be null? (as I agree having null key would be rather hard to resolve)

@kzlsakal
Copy link
Collaborator

kzlsakal commented Jun 27, 2022

According to the messages, currently, a nullable key field is still valid. What other methods can we use to accomplish this type lookup?

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

2 participants