graphql-crystal icon indicating copy to clipboard operation
graphql-crystal copied to clipboard

schema init

Open ExplosiveGM opened this issue 6 years ago • 0 comments

Can we declare schema in one place? Your kemal example has schema_string and type declaration:

  # A User
  type User implements UniqueId {
    # users first name
    firstName: String!
    # users last name
    lastName: String!
    # full name string for the user
    fullName: String! @deprecated(reason: "no need to construct this serverside..")
    # users role
    role: UserRole!
    # posts published
    # by this user
    posts: [Post!]
    # total number of posts
    # published by this user
    postsCount: Int!
  }
class User
  include ::GraphQL::ObjectType
  include UniqueId
  field :firstName { first_name }
  field :lastName { last_name }
  field :fullName { "#{@first_name} #{@last_name}" }
  field :posts { POSTS.select &.author.==(self)}
  field :postsCount { POSTS.select( &.author.==(self) ).size }
  field :role
end

rmosolgo/graphql-ruby uses some LateBoundType but it is magic. Can we add to schema.cr some simple method like: from_paths(paths : Array)

  1. It will search files in directories
  2. It will filter files by included GraphQL::ObjectType
  3. It will use method to_graphql
  4. it will create schema from converted strings

::GraphQL::Schema.from_paths(['path1', 'path2'])

ExplosiveGM avatar Sep 09 '19 17:09 ExplosiveGM