ash-project / ash_graphql

The extension for building GraphQL APIs with Ash
https://hexdocs.pm/ash_graphql
MIT License
73 stars 49 forks source link

Error when using `paginate_with: nil` and the default `read` action in Ash 3.0 #130

Closed miguel-s closed 7 months ago

miguel-s commented 7 months ago

I'm seeing an issue with AshGraphl and the new pagination in the default read action

I followed the upgrade guide and added paginate_with: nil to my graphql query

queries do
  list :list_categories, :read, paginate_with: nil
end

And call the query like this

query ListCategories {
  listCategories {
    id
    name
    icon
  }
}

The types are happy but when running the query I get this error

** (KeyError) key :id not found in: %{
  count: %Absinthe.Type.Field{
    identifier: :count,
    name: "count",
    description: "Total count on all pages",
    type: :integer,
    ...
  },
  results: %Absinthe.Type.Field{
    identifier: :results,
    name: "results",
    description: "The records contained in the page",
    type: %Absinthe.Type.List{
      of_type: %Absinthe.Type.NonNull{of_type: :category}
    },
    ...
  },
  ...
miguel-s commented 7 months ago

Here the full stacktrace

[error] 2954ac11-c219-4b0f-827c-26ce0dd525c6: Exception raised while resolving query.

** (KeyError) key :id not found in: %{
  count: %Absinthe.Type.Field{
    identifier: :count,
    name: "count",
    description: "Total count on all pages",
    type: :integer,
    deprecation: nil,
    args: %{},
    config: nil,
    triggers: [],
    middleware: [{Absinthe.Middleware.MapGet, :count}],
    complexity: nil,
    default_value: nil,
    __private__: [],
    definition: ProjectMa.Schema,
    __reference__: %{
      module: AshGraphql.Resource,
      location: %{
        line: 3296,
        file: "/.../project_ma/deps/ash_graphql/lib/resource/resource.ex"
      }
    }
  },
  results: %Absinthe.Type.Field{
    identifier: :results,
    name: "results",
    description: "The records contained in the page",
    type: %Absinthe.Type.List{
      of_type: %Absinthe.Type.NonNull{of_type: :category}
    },
    deprecation: nil,
    args: %{},
    config: nil,
    triggers: [],
    middleware: [{Absinthe.Middleware.MapGet, :results}],
    complexity: nil,
    default_value: nil,
    __private__: [],
    definition: ProjectMa.Schema,
    __reference__: %{
      module: AshGraphql.Resource,
      location: %{
        line: 3396,
        file: "/.../project_ma/deps/ash_graphql/lib/resource/resource.ex"
      }
    }
  },
  start_keyset: %Absinthe.Type.Field{
    identifier: :start_keyset,
    name: "start_keyset",
    description: "The first keyset in the results",
    type: :string,
    deprecation: nil,
    args: %{},
    config: nil,
    triggers: [],
    middleware: [{Absinthe.Middleware.MapGet, :start_keyset}],
    complexity: nil,
    default_value: nil,
    __private__: [],
    definition: ProjectMa.Schema,
    __reference__: %{
      module: AshGraphql.Resource,
      location: %{
        line: 3409,
        file: "/.../project_ma/deps/ash_graphql/lib/resource/resource.ex"
      }
    }
  },
  end_keyset: %Absinthe.Type.Field{
    identifier: :end_keyset,
    name: "end_keyset",
    description: "Th

    :erlang.map_get(:id, %{count: %Absinthe.Type.Field{identifier: :count, name: "count", description: "Total count on all pages", type: :integer, deprecation: nil, args: %{}, config: nil, triggers: [], middleware: [{Absinthe.Middleware.MapGet, :count}], complexity: nil, default_value: nil, __private__: [], definition: ProjectMa.Schema, __reference__: %{module: AshGraphql.Resource, location: %{line: 3296, file: "/.../project_ma/deps/ash_graphql/lib/resource/resource.ex"}}}, results: %Absinthe.Type.Field{identifier: :results, name: "results", description: "The records contained in the page", type: %Absinthe.Type.List{of_type: %Absinthe.Type.NonNull{of_type: :category}}, deprecation: nil, args: %{}, config: nil, triggers: [], middleware: [{Absinthe.Middleware.MapGet, :results}], complexity: nil, default_value: nil, __private__: [], definition: ProjectMa.Schema, __reference__: %{module: AshGraphql.Resource, location: %{line: 3396, file: "/.../Developer/project_ma/deps/ash_graphql/lib/resource/resource.ex"}}}, start_keyset: %Absinthe.Type.Field{identifier: :start_keyset, name: "start_keyset", description: "The first keyset in the results", type: :string, deprecation: nil, args: %{}, config: nil, triggers: [], middleware: [{Absinthe.Middleware.MapGet, :start_keyset}], complexity: nil, default_value: nil, __private__: [], definition: ProjectMa.Schema, __reference__: %{module: AshGraphql.Resource, location: %{line: 3409, file: "/.../project_ma/deps/ash_graphql/lib/resource/resource.ex"}}}, end_keyset: %Absinthe.Type.Field{identifier: :end_keyset, name: "end_keyset", description: "The last keyset in the results", type: :string, deprecation: nil, args: %{}, config: nil, triggers: [], middleware: [{Absinthe.Middleware.MapGet, :end_keyset}], complexity: nil, default_value: nil, __private__: [], definition: ProjectMa.Schema, __reference__: %{module: AshGraphql.Resource, location: %{line: 3417, file: "/.../project_ma/deps/ash_graphql/lib/resource/resource.ex"}}}, __typename: %Absinthe.Type.Field{identifier: :__typename, name: "__typename", description: "The name of the object type currently being queried.", type: :string, deprecation: nil, args: %{}, config: 0, triggers: %{}, middleware: [{{Absinthe.Middleware, :shim}, {:keyset_page_of_category, :__typename, [{:ref, Absinthe.Phase.Schema.Introspection, :typename}]}}], complexity: 0, default_value: nil, __private__: [], definition: Absinthe.Phase.Schema.Introspection, __reference__: %{module: Absinthe.Phase.Schema.Introspection, location: %{line: 74, file: "/.../project_ma/deps/absinthe/lib/absinthe/phase/schema/introspection.ex"}}}})
    (absinthe 1.7.6) lib/absinthe/resolution/projector.ex:136: Absinthe.Resolution.Projector.update_schema_node/2
    (absinthe 1.7.6) lib/absinthe/resolution/projector.ex:53: Absinthe.Resolution.Projector.do_collect/6
    (absinthe 1.7.6) lib/absinthe/resolution/projector.ex:41: Absinthe.Resolution.Projector.collect/3
    (absinthe 1.7.6) lib/absinthe/resolution/projector.ex:29: Absinthe.Resolution.Projector.project/5
    (absinthe 1.7.6) lib/absinthe/resolution.ex:190: Absinthe.Resolution.project/2
    (ash_graphql 1.0.0-rc.3) lib/graphql/resolver.ex:763: AshGraphql.Graphql.Resolver.validate_resolve_opts/6
    (ash_graphql 1.0.0-rc.3) lib/graphql/resolver.ex:425: AshGraphql.Graphql.Resolver.resolve/2
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:189: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:174: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:145: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:67: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
    (absinthe 1.7.6) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
    (absinthe_plug 1.5.8) lib/absinthe/plug.ex:536: Absinthe.Plug.run_query/4
    (absinthe_plug 1.5.8) lib/absinthe/plug.ex:290: Absinthe.Plug.call/2
    (phoenix 1.7.12) lib/phoenix/router/route.ex:42: Phoenix.Router.Route.call/2
    (phoenix 1.7.12) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5