ziprandom / kemal-graphql-example

Exploring graphql-crystal with kemal & graphiql
MIT License
35 stars 5 forks source link

Error with Hello World schema #6

Open kefahi opened 5 years ago

kefahi commented 5 years ago

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 commented 5 years ago

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
ziprandom commented 5 years ago

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