Absinthe: Validation fails to identify non existant fragment

Created on 28 Jun 2017  路  5Comments  路  Source: absinthe-graphql/absinthe

I'm getting this error when running against a schema that i generated based off of interpolation.
it is pretty close to a hand written schema that i previously used.

stack trace is

     ** (UndefinedFunctionError) function nil.schema_node/0 is undefined or private
     stacktrace:
       nil.schema_node()
       (absinthe) lib/absinthe/phase/document/validation/fields_on_correct_type.ex:37: anonymous fn/5 in Absinthe.Phase.Document.Validation.FieldsOnCorrectType.handle_node/2
       (elixir) lib/enum.ex:1229: Enum."-map/2-lists^map/1-0-"/2
       (absinthe) lib/absinthe/phase/document/validation/fields_on_correct_type.ex:23: Absinthe.Phase.Document.Validation.FieldsOnCorrectType.handle_node/2
       (absinthe) lib/absinthe/blueprint/transform.ex:14: anonymous fn/3 in Absinthe.Blueprint.Transform.prewalk/2
       (absinthe) lib/absinthe/blueprint/transform.ex:109: Absinthe.Blueprint.Transform.node_with_children/5
       (elixir) lib/enum.ex:1325: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
       (elixir) lib/enum.ex:1325: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
       (absinthe) lib/absinthe/blueprint/transform.ex:123: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
       (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
       (absinthe) lib/absinthe/blueprint/transform.ex:113: Absinthe.Blueprint.Transform.node_with_children/5
       (elixir) lib/enum.ex:1325: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
       (elixir) lib/enum.ex:1325: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
       (absinthe) lib/absinthe/blueprint/transform.ex:123: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
       (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
       (absinthe) lib/absinthe/blueprint/transform.ex:113: Absinthe.Blueprint.Transform.node_with_children/5
       (absinthe) lib/absinthe/blueprint/transform.ex:13: Absinthe.Blueprint.Transform.prewalk/2
       (absinthe) lib/absinthe/phase/document/validation/fields_on_correct_type.ex:15: Absinthe.Phase.Document.Validation.FieldsOnCorrectType.run/2
       (absinthe) lib/absinthe/pipeline.ex:247: Absinthe.Pipeline.run_phase/3
       (absinthe) lib/absinthe.ex:225: Absinthe.run/3

fragments (abridged)

    fragment Plan on Plan {
      notes { ...String }
    }

i've looked over the fragments, and tried to get rid of ones that weren't related to the return.

any help on this would be really great!

Bug

Most helpful comment

It looks like you have a reference to a non-existing fragment:

notes { ...String }

No String fragment is defined.

The validation should, of course, handle this better, but it appears that the document _is_ invalid.

All 5 comments

It looks like you have a reference to a non-existing fragment:

notes { ...String }

No String fragment is defined.

The validation should, of course, handle this better, but it appears that the document _is_ invalid.

Here's the quick-and-dirty iex snippet I used to find this, btw:

iex(1)> data = File.read!("fragments.graphql")
iex(2)> references = Regex.scan(~r/\.\.\.(\S+)/, data) |> Enum.map(&List.last/1) |> Enum.uniq
iex(3)> references |> Enum.reject(&Regex.match?(~r/fragment #{&1}/, data))
["String"]

Worth noting, BTW, that because String is a built-in type name, it's probably not the best choice for a fragment name. I'd suggest a naming scheme like TypeFields for any given Type (or something with more semantic value in the context of the fragment use).

this is an issue with referencing a built in scalar type as an object type.
the use of String is an artifact in the generator i made. however, it wasn't obvious to me that i couldn't do this (the graphQL didn't look crazy, and it didn't stand out to me that this was illegal).

also, you guys are amazing at your ability to spot query problems.

so, is there a solution to this?

i should have enough information to make a PR with better error reporting

Fixed in master.

Was this page helpful?
0 / 5 - 0 ratings