Bladeren bron

Add rake task to dump GraphQL schema for Relay

Andrew Swistak 6 jaren geleden
bovenliggende
commit
f44f9c762e
2 gewijzigde bestanden met toevoegingen van 204 en 0 verwijderingen
  1. 189 0
      db/schema.graphql
  2. 15 0
      lib/tasks/graphql/schema.rake

+ 189 - 0
db/schema.graphql

@@ -0,0 +1,189 @@
+"""
+Autogenerated return type of CreatePokemon
+"""
+type CreatePokemonPayload {
+  errors: [Error!]!
+  pokemon: Pokemon
+}
+
+type Error {
+  message: String!
+  type: String
+}
+
+type Mutation {
+  createPokemon(nickname: String, pokedexNumber: ID!): CreatePokemonPayload
+  uploadManyPokemon(base64EncodedPokemonFiles: [String!]!): UploadManyPokemonPayload
+  uploadPokemon(base64EncodedPokemonFile: String!): UploadPokemonPayload
+}
+
+"""
+An object with an ID.
+"""
+interface Node {
+  """
+  ID of the object.
+  """
+  id: ID!
+}
+
+"""
+Information about pagination in a connection.
+"""
+type PageInfo {
+  """
+  When paginating forwards, the cursor to continue.
+  """
+  endCursor: String
+
+  """
+  When paginating forwards, are there more items?
+  """
+  hasNextPage: Boolean!
+
+  """
+  When paginating backwards, are there more items?
+  """
+  hasPreviousPage: Boolean!
+
+  """
+  When paginating backwards, the cursor to continue.
+  """
+  startCursor: String
+}
+
+"""
+Returns a singular pokemon
+"""
+type Pokemon implements Node {
+  createdAt: Time
+  id: ID!
+  iid: ID!
+  nickname: String
+  pokedexNumber: Int
+  updatedAt: Time
+}
+
+"""
+The connection type for Pokemon.
+"""
+type PokemonConnection {
+  """
+  A list of edges.
+  """
+  edges: [PokemonEdge]
+
+  """
+  A list of nodes.
+  """
+  nodes: [Pokemon]
+
+  """
+  Information to aid in pagination.
+  """
+  pageInfo: PageInfo!
+}
+
+"""
+An edge in a connection.
+"""
+type PokemonEdge {
+  """
+  A cursor for use in pagination.
+  """
+  cursor: String!
+
+  """
+  The item at the end of the edge.
+  """
+  node: Pokemon
+}
+
+"""
+The root of this schema
+"""
+type Query {
+  """
+  Fetches one or more pokemon
+  """
+  manyPokemon(id: String, ids: [String!], iid: ID, iids: [ID!], nickname: String, nicknames: [String!], pokedexNumber: Int, pokedexNumbers: [Int!]): [Pokemon!]!
+
+  """
+  Fetches an object given its ID.
+  """
+  node(
+    """
+    ID of the object.
+    """
+    id: ID!
+  ): Node
+
+  """
+  Fetches a list of objects given a list of IDs.
+  """
+  nodes(
+    """
+    IDs of the objects.
+    """
+    ids: [ID!]!
+  ): [Node]!
+
+  """
+  Fetches exactly zero or one pokemon
+  """
+  pokemon(id: String, ids: [String!], iid: ID, iids: [ID!], nickname: String, nicknames: [String!], pokedexNumber: Int, pokedexNumbers: [Int!]): Pokemon
+
+  """
+  Fetches one or more pokemon for Relay
+  """
+  pokemonConnection(
+    """
+    Returns the elements in the list that come after the specified cursor.
+    """
+    after: String
+
+    """
+    Returns the elements in the list that come before the specified cursor.
+    """
+    before: String
+
+    """
+    Returns the first _n_ elements from the list.
+    """
+    first: Int
+    id: String
+    ids: [String!]
+    iid: ID
+    iids: [ID!]
+
+    """
+    Returns the last _n_ elements from the list.
+    """
+    last: Int
+    nickname: String
+    nicknames: [String!]
+    pokedexNumber: Int
+    pokedexNumbers: [Int!]
+  ): PokemonConnection!
+}
+
+"""
+Time represented in ISO 8601
+"""
+scalar Time
+
+"""
+Autogenerated return type of UploadManyPokemon
+"""
+type UploadManyPokemonPayload {
+  errors: [Error!]!
+  pokemon: [Pokemon!]
+}
+
+"""
+Autogenerated return type of UploadPokemon
+"""
+type UploadPokemonPayload {
+  errors: [Error!]!
+  pokemon: Pokemon
+}

+ 15 - 0
lib/tasks/graphql/schema.rake

@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+require 'English'
+
+namespace :graphql do
+  namespace :schema do
+    desc 'Dumps the graphql schema'
+    task dump: :environment do
+      schema = GraphQL::Schema::Printer.new(PokemonTradeSchema).print_schema
+      File.open(Rails.root.join('db', 'schema.graphql'), 'w') do |f|
+        f.puts schema
+      end
+    end
+  end
+end