kemal-graphql-example icon indicating copy to clipboard operation
kemal-graphql-example copied to clipboard

Error with Hello World schema

Open kefahi opened this issue 6 years ago • 2 comments

When enabling hello_world_schema the following compiler error is thrown:

query "hello" { "world" }
      ^----
Error: undefined method 'query' for GraphQL::Schema::Schema (with ... yield) and Kemal::GraphQL:Module (current scope)

The way how that hello world example is written is very nice and good for simple cases. But it seems some maintenance is needed there.

kefahi avatar Oct 23 '19 23:10 kefahi

I figured it out, this was the "old" style that seems to be deprecated now. (I like the simpler old style btw :) )

The change I had to do to the Hello world example to work is the following

require "graphql-crystal"

module Kemal::GraphQL
  module RootQuery
    include ::GraphQL::ObjectType
    extend self
    field "hello" { "world" }
  end

  HELLO_WORLD_SCHEMA = ::GraphQL::Schema.from_schema(
    %{
      schema {
        query: RootQuery
      }

      type RootQuery {
        hello: String
      }
    }
  )
  HELLO_WORLD_SCHEMA.query_resolver = RootQuery
end

kefahi avatar Oct 23 '19 23:10 kefahi

hey Kefah,

thanks for your help. If you like you could open a pull request to fix the example!

Kefah T. Issa writes:

I figured it out, this was the "old" style that seems to be deprecated now. (I like the simpler old style btw :) )

The change I had to do to the Hello world example is work is the following

require "graphql-crystal"

module Kemal::GraphQL
  module RootQuery
    include ::GraphQL::ObjectType
    extend self
    field "hello" { "world" }
  end

  HELLO_WORLD_SCHEMA = ::GraphQL::Schema.from_schema(
    %{
      schema {
        query: RootQuery
      }

      type RootQuery {
        hello: String
      }
    }
  )
  HELLO_WORLD_SCHEMA.query_resolver = RootQuery
end

ziprandom avatar Oct 24 '19 20:10 ziprandom