浏览代码

introspection implementation

Ruslan Talpa 9 年之前
父节点
当前提交
dc366ef3b0
共有 13 个文件被更改,包括 2279 次插入58 次删除
  1. 23 6
      graphql/execute.lua
  2. 605 0
      graphql/introspection.lua
  3. 1 1
      graphql/parse.lua
  4. 13 8
      graphql/rules.lua
  5. 62 11
      graphql/schema.lua
  6. 39 13
      graphql/types.lua
  7. 10 10
      graphql/util.lua
  8. 29 8
      graphql/validate.lua
  9. 0 0
      tests/data/species.lua
  10. 162 0
      tests/data/todo.lua
  11. 1333 0
      tests/introspection.lua
  12. 1 1
      tests/rules.lua
  13. 1 0
      tests/runner.lua

+ 23 - 6
graphql/execute.lua

@@ -1,6 +1,8 @@
 local path = (...):gsub('%.[^%.]+$', '')
 local types = require(path .. '.types')
 local util = require(path .. '.util')
+local introspection = require(path .. '.introspection')
+local cjson = require 'cjson' -- needs to be cloned from here https://github.com/openresty/lua-cjson for cjson.empty_array feature
 
 local function typeFromAST(node, schema)
   local innerType
@@ -149,7 +151,7 @@ local function completeValue(fieldType, result, subSelections, context)
 
   if fieldTypeName == 'NonNull' then
     local innerType = fieldType.ofType
-    local completedResult = completeValue(innerType, result, context)
+    local completedResult = completeValue(innerType, result, subSelections, context)
 
     if completedResult == nil then
       error('No value provided for non-null ' .. innerType.name)
@@ -163,6 +165,8 @@ local function completeValue(fieldType, result, subSelections, context)
   end
 
   if fieldTypeName == 'List' then
+    if result == cjson.empty_array then return result end
+    
     local innerType = fieldType.ofType
 
     if type(result) ~= 'table' then
@@ -177,9 +181,12 @@ local function completeValue(fieldType, result, subSelections, context)
     return values
   end
 
-  if fieldTypeName == 'Scalar' or fieldTypeName == 'Enum' then
+  if fieldTypeName == 'Scalar' then
     return fieldType.serialize(result)
   end
+  if fieldTypeName == 'Enum' then
+    return fieldType:serialize(result)
+  end
 
   if fieldTypeName == 'Object' then
     return evaluateSelections(fieldType, result, subSelections, context)
@@ -195,7 +202,16 @@ local function getFieldEntry(objectType, object, fields, context)
   local firstField = fields[1]
   local fieldName = firstField.name.value
   local responseKey = getFieldResponseKey(firstField)
-  local fieldType = objectType.fields[fieldName]
+  local fieldType
+  if fieldName == '__schema' then
+    fieldType = introspection.SchemaMetaFieldDef
+  elseif fieldName == '__type' then
+    fieldType = introspection.TypeMetaFieldDef
+  elseif fieldName == '__typename' then
+    fieldType = introspection.TypeNameMetaFieldDef
+  else
+    fieldType = objectType.fields[fieldName]
+  end
 
   if fieldType == nil then
     return nil
@@ -206,9 +222,9 @@ local function getFieldEntry(objectType, object, fields, context)
     argumentMap[argument.name.value] = argument
   end
 
-  local arguments = util.map(fieldType.arguments, function(argument, name)
+  local arguments = util.map(fieldType.arguments or {}, function(argument, name)
     local supplied = argumentMap[name] and argumentMap[name].value
-    return supplied and util.coerceValue(supplied, argument, context.variables) or argument.defaultValue
+    return supplied and util.coerceValue(argumentMap[name].value, argument.kind, context.variables) or argument.defaultValue
   end)
 
   local info = {
@@ -234,7 +250,8 @@ evaluateSelections = function(objectType, object, selections, context)
   local groupedFieldSet = collectFields(objectType, selections, {}, {}, context)
 
   return util.map(groupedFieldSet, function(fields)
-    return getFieldEntry(objectType, object, fields, context)
+    local v = getFieldEntry(objectType, object, fields, context)
+    if v ~= nil then return v else return cjson.null end
   end)
 end
 

+ 605 - 0
graphql/introspection.lua

@@ -0,0 +1,605 @@
+local path = (...):gsub('%.[^%.]+$', '')
+local types = require(path .. '.types')
+local util = require(path .. '.util')
+local cjson = require 'cjson' -- needs to be cloned from here https://github.com/openresty/lua-cjson for cjson.empty_array feature
+local function isNullish(value)
+  return value == nil
+end
+local function instanceof(t, s)
+  return t.__type == s
+end
+local function resolveDirective(directive)
+  local res = {}
+  if directive.onQuery then table.insert(res, 'QUERY') end
+  if directive.onMutation then table.insert(res, 'MUTATION') end
+  if directive.onSubscription then table.insert(res, 'SUBSCRIPTION') end
+  if directive.onField then table.insert(res, 'FIELD') end
+  if directive.onFragmentDefinition then table.insert(res, 'FRAGMENT_DEFINITION') end
+  if directive.onFragmentSpread then table.insert(res, 'FRAGMENT_SPREAD') end
+  if directive.onInlineFragment then table.insert(res, 'INLINE_FRAGMENT') end
+  return res
+end
+local function mapToList(m)
+  local r = {}
+  for k,v in pairs(m) do
+    table.insert(r, v)
+  end
+  return r
+end
+local __Schema, __Directive, __DirectiveLocation, __Type, __Field, __InputValue,__EnumValue, TypeKind, __TypeKind, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, astFromValue, printAst, printers
+local DirectiveLocation = {
+  QUERY =  'QUERY', MUTATION =  'MUTATION', SUBSCRIPTION =  'SUBSCRIPTION', FIELD =  'FIELD', FRAGMENT_DEFINITION =  'FRAGMENT_DEFINITION', FRAGMENT_SPREAD =  'FRAGMENT_SPREAD', INLINE_FRAGMENT =  'INLINE_FRAGMENT'
+}
+
+__Schema = types.object({
+  name = '__Schema',
+  description =
+    'A GraphQL Schema defines the capabilities of a GraphQL server. It ' ..
+    'exposes all available types and directives on the server, as well as ' ..
+    'the entry points for query, mutation, and subscription operations.',
+  fields = function() return {
+    types = {
+      description = 'A list of all types supported by this server.',
+      kind = types.nonNull(types.list(types.nonNull(__Type))),
+      resolve = function(schema)
+        local typeMap = schema:getTypeMap(); local res = {}
+        for k,v in pairs(typeMap) do table.insert(res, typeMap[k]) end; return res
+      end
+    },
+    queryType = {
+      description = 'The type that query operations will be rooted at.',
+      kind = types.nonNull(__Type),
+      resolve = function(schema) return schema:getQueryType() end
+    },
+    mutationType = {
+      description = 'If this server supports mutation, the type that ' ..
+                   'mutation operations will be rooted at.',
+      kind = __Type,
+      resolve = function(schema) return schema:getMutationType() end
+    },
+    subscriptionType = {
+      description = 'If this server support subscription, the type that ' ..
+                   'subscription operations will be rooted at.',
+      kind = __Type,
+      resolve = function(schema) return schema:getSubscriptionType() end
+    },
+    directives = {
+      description = 'A list of all directives supported by this server.',
+      kind = 
+        types.nonNull(types.list(types.nonNull(__Directive))),
+      resolve = function(schema) return schema.directives end
+    }
+  } end
+});
+
+__Directive = types.object({
+  name = '__Directive',
+  description =
+    'A Directive provides a way to describe alternate runtime execution and ' ..
+    'type validation behavior in a GraphQL document.' ..
+    '\n\nIn some cases, you need to provide options to alter GraphQL’s ' ..
+    'execution behavior in ways field arguments will not suffice, such as ' ..
+    'conditionally including or skipping a field. Directives provide this by ' ..
+    'describing additional information to the executor.',
+  fields = function() return {
+    name = types.nonNull(types.string),
+    description = types.string,
+    locations = {
+      kind = types.nonNull(types.list(types.nonNull(
+        __DirectiveLocation
+      ))), resolve = resolveDirective
+    },
+    args = {
+      kind = 
+        types.nonNull(types.list(types.nonNull(__InputValue))),
+      --resolve = function(directive) return directive.arguments or {} end
+      resolve = function(field)
+        local args = {}
+        local transform = function(a, n)
+          if a.__type then
+            return {kind = a, name = n}
+          else
+            if not a.name then
+              local r = {name = n}
+              for k,v in pairs(a) do
+                r[k] = v
+              end
+              return r
+            else
+              return a
+            end
+          end
+        end
+        for k, v in pairs(field.arguments or {}) do table.insert(args, transform(v, k)) end
+        -- p(args)
+        -- return args
+        if #args > 0 then return args else return cjson.empty_array end
+      end
+    },
+    -- NOTE = the following three fields are deprecated and are no longer part
+    -- of the GraphQL specification.
+    onOperation = {
+      deprecationReason = 'Use `locations`.',
+      kind = types.nonNull(types.boolean),
+      resolve = function(d) return
+        d.locations:find(DirectiveLocation.QUERY) ~= nil or
+        d.locations:find(DirectiveLocation.MUTATION) ~= nil or
+        d.locations:find(DirectiveLocation.SUBSCRIPTION) ~= nil end
+    },
+    onFragment = {
+      deprecationReason = 'Use `locations`.',
+      kind = types.nonNull(types.boolean),
+      resolve = function(d) return
+        d.locations:find(DirectiveLocation.FRAGMENT_SPREAD) ~= nil or
+        d.locations:find(DirectiveLocation.INLINE_FRAGMENT) ~= nil or
+        d.locations:find(DirectiveLocation.FRAGMENT_DEFINITION) ~= nil end
+    },
+    onField = {
+      deprecationReason = 'Use `locations`.',
+      kind = types.nonNull(types.boolean),
+      resolve = function(d) return d.locations:find(DirectiveLocation.FIELD) ~= nil end
+    }
+  } end
+});
+
+__DirectiveLocation = types.enum({
+  name = '__DirectiveLocation',
+  description =
+    'A Directive can be adjacent to many parts of the GraphQL language, a ' ..
+    '__DirectiveLocation describes one such possible adjacencies.',
+  values = {
+    QUERY = {
+      value = DirectiveLocation.QUERY,
+      description = 'Location adjacent to a query operation.'
+    },
+    MUTATION = {
+      value = DirectiveLocation.MUTATION,
+      description = 'Location adjacent to a mutation operation.'
+    },
+    SUBSCRIPTION = {
+      value = DirectiveLocation.SUBSCRIPTION,
+      description = 'Location adjacent to a subscription operation.'
+    },
+    FIELD = {
+      value = DirectiveLocation.FIELD,
+      description = 'Location adjacent to a field.'
+    },
+    FRAGMENT_DEFINITION = {
+      value = DirectiveLocation.FRAGMENT_DEFINITION,
+      description = 'Location adjacent to a fragment definition.'
+    },
+    FRAGMENT_SPREAD = {
+      value = DirectiveLocation.FRAGMENT_SPREAD,
+      description = 'Location adjacent to a fragment spread.'
+    },
+    INLINE_FRAGMENT = {
+      value = DirectiveLocation.INLINE_FRAGMENT,
+      description = 'Location adjacent to an inline fragment.'
+    },
+  }
+});
+
+__Type = types.object({
+  name = '__Type',
+  description =
+    'The fundamental unit of any GraphQL Schema is the type. There are ' ..
+    'many kinds of types in GraphQL as represented by the `__TypeKind` enum.' ..
+    '\n\nDepending on the kind of a type, certain fields describe ' ..
+    'information about that type. Scalar types provide no information ' ..
+    'beyond a name and description, while Enum types provide their values. ' ..
+    'Object and Interface types provide the fields they describe. Abstract ' ..
+    'types, Union and Interface, provide the Object types possible ' ..
+    'at runtime. List and NonNull types compose other types.',
+  fields = function() return {
+    kind = {
+      kind = types.nonNull(__TypeKind),
+      resolve = function (type)
+        if instanceof(type, 'Scalar') then
+          return TypeKind.SCALAR;
+        elseif instanceof(type, 'Object') then
+          return TypeKind.OBJECT;
+        elseif instanceof(type, 'Interface') then
+          return TypeKind.INTERFACE;
+        elseif instanceof(type, 'Union') then
+          return TypeKind.UNION;
+        elseif instanceof(type, 'Enum') then
+          return TypeKind.ENUM;
+        elseif instanceof(type, 'InputObject') then
+          return TypeKind.INPUT_OBJECT;
+        elseif instanceof(type, 'List') then
+          return TypeKind.LIST;
+        elseif instanceof(type, 'NonNull') then
+          return TypeKind.NON_NULL;
+        end
+        error('Unknown kind of kind = ' .. type);
+      end
+    },
+    name = types.string,
+    description = types.string,
+    fields = {
+      kind = types.list(types.nonNull(__Field)),
+      arguments = {
+        -- includeDeprecated = types.boolean 
+        includeDeprecated = { kind = types.boolean, defaultValue = false }
+      },
+      resolve = function(t, args)
+        if instanceof(t, 'Object') or
+            instanceof(t, 'Interface') then
+          
+          local fieldMap = t.fields;
+          local fields = {}; for k,v in pairs(fieldMap) do table.insert(fields, fieldMap[k]) end
+          if not args.includeDeprecated then
+            fields = util.filter(fields, function(field) return not field.deprecationReason end);
+          end
+          if #fields > 0 then return fields else return cjson.empty_array end
+        end
+        return nil;
+      end
+    },
+    interfaces = {
+      kind = types.list(types.nonNull(__Type)),
+      resolve = function(type)
+        if instanceof(type, 'Object') then
+          return type.interfaces and type.interfaces or cjson.empty_array;
+        end
+      end
+    },
+    possibleTypes = {
+      kind = types.list(types.nonNull(__Type)),
+      resolve = function(type, args, context, obj)
+        if instanceof(type, 'Interface') or
+            instanceof(type, 'Union') then
+          return context.schema:getPossibleTypes(type);
+        end
+      end
+    },
+    enumValues = {
+      kind = types.list(types.nonNull(__EnumValue)),
+      arguments = {
+        -- includeDeprecated = types.boolean
+        includeDeprecated = { kind = types.boolean, defaultValue = false }
+      },
+      resolve = function(type, args)
+        if instanceof(type, 'Enum') then
+          local values = type.values;
+          if not args.includeDeprecated then
+            values = util.filter(values, function(value) return not value.deprecationReason end);
+          end
+          return mapToList(values);
+        end
+      end
+    },
+    inputFields = {
+      kind = types.list(types.nonNull(__InputValue)),
+      resolve = function(type)
+        if instanceof(type, 'InputObject') then
+          local fieldMap = type.fields;
+          local fields = {}; for k,v in pairs(fieldMap) do table.insert(fields, fieldMap[k]) end; return fields
+        end
+      end
+    },
+    ofType = { kind = __Type }
+  } end
+});
+
+__Field = types.object({
+  name = '__Field',
+  description =
+    'Object and Interface types are described by a list of Fields, each of ' ..
+    'which has a name, potentially a list of arguments, and a return type.',
+  fields = function() return {
+    name = types.nonNull(types.string),
+    description = types.string,
+    args = {
+      -- kind = types.list(__InputValue),
+      kind = types.nonNull(types.list(types.nonNull(__InputValue))),
+      resolve = function(field)
+        local args = {}
+        local transform = function(a, n)
+          if a.__type then
+            return {kind = a, name = n}
+          else
+            if not a.name then
+              local r = {name = n}
+              for k,v in pairs(a) do
+                r[k] = v
+              end
+              return r
+            else
+              return a
+            end
+          end
+        end
+        for k, v in pairs(field.arguments or {}) do table.insert(args, transform(v, k)) end
+        -- return args
+        if #args > 0 then return args else return cjson.empty_array end
+      end
+    },
+    type = { kind = types.nonNull(__Type), resolve = function(field) return field.kind end },
+    isDeprecated = {
+      kind = types.nonNull(types.boolean),
+      resolve = function(field) return not isNullish(field.deprecationReason) end
+    },
+    deprecationReason = types.string
+
+  } end
+});
+
+__InputValue = types.object({
+  name = '__InputValue',
+  description =
+    'Arguments provided to Fields or Directives and the input fields of an ' ..
+    'InputObject are represented as Input Values which describe their type ' ..
+    'and optionally a default value.',
+  fields = function() return {
+    name = types.nonNull(types.string),
+    description = types.string,
+    type = { kind = types.nonNull(__Type), resolve = function(field) return field.kind end },
+    defaultValue = {
+      kind = types.string,
+      description =
+        'A GraphQL-formatted string representing the default value for this ' ..
+        'input value.',
+      resolve = function(inputVal) if isNullish(inputVal.defaultValue)
+        then return nil
+        else return printAst(astFromValue(inputVal.defaultValue, inputVal)) end end
+    }
+  } end
+});
+
+__EnumValue = types.object({
+  name = '__EnumValue',
+  description =
+    'One possible value for a given Enum. Enum values are unique values, not ' ..
+    'a placeholder for a string or numeric value. However an Enum value is ' ..
+    'returned in a JSON response as a string.',
+  fields = function() return {
+    name = types.nonNull(types.string),
+    description = types.string,
+    isDeprecated = {
+      kind = types.nonNull(types.boolean),
+      resolve = function(enumValue) return not isNullish(enumValue.deprecationReason) end
+    },
+    deprecationReason = 
+      types.string
+
+  } end
+});
+
+TypeKind = {
+  SCALAR = 'SCALAR',
+  OBJECT = 'OBJECT',
+  INTERFACE = 'INTERFACE',
+  UNION = 'UNION',
+  ENUM = 'ENUM',
+  INPUT_OBJECT = 'INPUT_OBJECT',
+  LIST = 'LIST',
+  NON_NULL = 'NON_NULL'
+};
+
+__TypeKind = types.enum({
+  name = '__TypeKind',
+  description = 'An enum describing what kind of type a given `__Type` is.',
+  values = {
+    SCALAR = {
+      value = TypeKind.SCALAR,
+      description = 'Indicates this type is a scalar.'
+    },
+    OBJECT = {
+      value = TypeKind.OBJECT,
+      description = 'Indicates this type is an object. ' ..
+                   '`fields` and `interfaces` are valid fields.'
+    },
+    INTERFACE = {
+      value = TypeKind.INTERFACE,
+      description = 'Indicates this type is an interface. ' ..
+                   '`fields` and `possibleTypes` are valid fields.'
+    },
+    UNION = {
+      value = TypeKind.UNION,
+      description = 'Indicates this type is a union. ' ..
+                   '`possibleTypes` is a valid field.'
+    },
+    ENUM = {
+      value = TypeKind.ENUM,
+      description = 'Indicates this type is an enum. ' ..
+                   '`enumValues` is a valid field.'
+    },
+    INPUT_OBJECT = {
+      value = TypeKind.INPUT_OBJECT,
+      description = 'Indicates this type is an input object. ' ..
+                   '`inputFields` is a valid field.'
+    },
+    LIST = {
+      value = TypeKind.LIST,
+      description = 'Indicates this type is a list. ' ..
+                   '`ofType` is a valid field.'
+    },
+    NON_NULL = {
+      value = TypeKind.NON_NULL,
+      description = 'Indicates this type is a non-null. ' ..
+                   '`ofType` is a valid field.'
+    }
+  }
+});
+
+--
+-- Note that these are GraphQLFieldDefinition and not GraphQLFieldConfig,
+-- so the format for args is different.
+--
+
+SchemaMetaFieldDef = {
+  name = '__schema',
+  kind = types.nonNull(__Schema),
+  description = 'Access the current type schema of this server.',
+  arguments = {},
+  resolve = function(source, args, context, obj) return context.schema  end
+};
+
+TypeMetaFieldDef = {
+  name = '__type',
+  kind = __Type,
+  description = 'Request the type information of a single type.',
+  arguments = {
+    name = types.nonNull(types.string)
+  }
+  --,resolve = function(source, { name } = { name = string }, context, { schema })
+  --  return schema.getType(name) end
+};
+
+TypeNameMetaFieldDef = {
+  name = '__typename',
+  kind = types.nonNull(types.string),
+  description = 'The name of the current Object type at runtime.',
+  arguments = {},
+  resolve = function(source, args, context, obj) return obj.parentType.name end
+};
+
+
+-- Produces a GraphQL Value AST given a lua value.
+
+-- Optionally, a GraphQL type may be provided, which will be used to
+-- disambiguate between value primitives.
+
+-- | JSON Value    | GraphQL Value        |
+-- | ------------- | -------------------- |
+-- | Object        | Input Object         |
+-- | Array         | List                 |
+-- | Boolean       | Boolean              |
+-- | String        | String / Enum Value  |
+-- | Number        | Int / Float          |
+
+local Kind = {
+  LIST = 'ListValue',
+  BOOLEAN = 'BooleanValue',
+  FLOAT = 'FloatValue',
+  INT = 'IntValue',
+  FLOAT = 'FloatValue',
+  ENUM = 'EnumValue',
+  STRING = 'StringValue',
+  OBJECT_FIELD = 'ObjectField',
+  NAME = 'Name',
+  OBJECT = 'ObjectValue'
+}
+
+printers = {
+  IntValue = function(v) return v.value end,
+  FloatValue = function(v) return v.value end,
+  StringValue = function(v) return cjson.encode(v.value) end,
+  BooleanValue = function(v) return cjson.encode(v.value) end,
+  EnumValue = function(v) return v.value end,
+  ListValue = function(v) return '[' .. table.concat(util.map(v.values, printAst), ', ') .. ']' end,
+  ObjectValue = function(v) return '{' .. table.concat(util.map(v.fields, printAst), ', ') .. '}' end,
+  ObjectField = function(v) return v.name .. ': ' .. v.value end
+}
+
+printAst = function(v)
+  return printers[v.kind](v)
+end
+
+astFromValue = function(value, tt)
+  -- Ensure flow knows that we treat function params as const.
+  local _value = value
+
+  if instanceof(tt,'NonNull') then
+    -- Note: we're not checking that the result is non-null.
+    -- This function is not responsible for validating the input value.
+    return astFromValue(_value, tt.ofType)
+  end
+
+  if isNullish(_value) then
+    return nil
+  end
+
+  -- Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
+  -- the value is not an array, convert the value using the list's item type.
+  if type(_value) == 'table' and #_value > 0 then
+    local itemType = instanceof(tt, 'List') and tt.ofType or nil
+    return {
+      kind = Kind.LIST,
+      values = util.map(_value, function(item)
+        local itemValue = astFromValue(item, itemType)
+        assert(itemValue, 'Could not create AST item.')
+        return itemValue
+      end)
+    }
+  elseif instanceof(tt, 'List') then
+    -- Because GraphQL will accept single values as a "list of one" when
+    -- expecting a list, if there's a non-array value and an expected list type,
+    -- create an AST using the list's item type.
+    return astFromValue(_value, tt.ofType)
+  end
+
+  if type(_value) == 'boolean' then
+    return { kind = Kind.BOOLEAN, value = _value }
+  end
+
+  -- JavaScript numbers can be Float or Int values. Use the GraphQLType to
+  -- differentiate if available, otherwise prefer Int if the value is a
+  -- valid Int.
+  if type(_value) == 'number' then
+    local stringNum = String(_value)
+    local isIntValue = _value%1 == 0
+    if isIntValue then
+      if tt == types.float then
+        return { kind =  Kind.FLOAT, value = stringNum .. '.0' }
+      end
+      return { kind = Kind.INT, value = stringNum }
+    end
+    return { kind = Kind.FLOAT, value = stringNum }
+  end
+
+  -- JavaScript strings can be Enum values or String values. Use the
+  -- GraphQLType to differentiate if possible.
+  if type(_value) == 'string' then
+    if instanceof(tt, 'Enum') and _value:match('/^[_a-zA-Z][_a-zA-Z0-9]*$/') then
+      return { kind =Kind.ENUM, value = _value }
+    end
+    -- Use JSON stringify, which uses the same string encoding as GraphQL,
+    -- then remove the quotes.
+    return {
+      kind = Kind.STRING,
+      value = (cjson.encode(_value)):sub(1, -1)
+    }
+  end
+
+  -- last remaining possible typeof
+  assert(type(_value) == 'table')
+  assert(_value ~= nil)
+
+  -- Populate the fields of the input object by creating ASTs from each value
+  -- in the JavaScript object.
+  local fields = {}
+  for fieldName,v in pairs(_value) do
+    local fieldType
+    if instanceof(tt, 'InputObject') then
+      local fieldDef = tt.fields[fieldName];
+      fieldType = fieldDef and fieldDef.kind;
+    end
+    local fieldValue = astFromValue(_value[fieldName], fieldType);
+    if fieldValue then
+      table.insert(fields, {
+        kind = Kind.OBJECT_FIELD,
+        name = { kind = Kind.NAME, value = fieldName },
+        value = fieldValue
+      })
+    end
+  end
+  return { kind = Kind.OBJECT, fields = fields }
+end
+
+return {
+  __Schema = __Schema,
+  __Directive = __Directive,
+  __DirectiveLocation = __DirectiveLocation,
+  __Type = __Type,
+  __Field = __Field,
+  __EnumValue = __EnumValue,
+  TypeKind = TypeKind,
+  __TypeKind = __TypeKind,
+  SchemaMetaFieldDef = SchemaMetaFieldDef,
+  TypeMetaFieldDef = TypeMetaFieldDef,
+  TypeNameMetaFieldDef = TypeNameMetaFieldDef
+
+}
+

+ 1 - 1
graphql/parse.lua

@@ -237,7 +237,7 @@ local function cDirective(name, arguments)
 end
 
 -- Simple types
-local rawName = R('az', 'AZ') * (P'_' + R'09' + R('az', 'AZ')) ^ 0
+local rawName = (P'_' + R('az', 'AZ')) * (P'_' + R'09' + R('az', 'AZ')) ^ 0
 local name = rawName / cName
 local fragmentName = (rawName - ('on' * -rawName)) / cName
 local alias = ws * name * P':' * ws / cAlias

+ 13 - 8
graphql/rules.lua

@@ -2,6 +2,7 @@ local path = (...):gsub('%.[^%.]+$', '')
 local types = require(path .. '.types')
 local util = require(path .. '.util')
 
+local getParentField = require(path .. '.schema').getParentField
 local rules = {}
 
 function rules.uniqueOperationNames(node, context)
@@ -31,16 +32,14 @@ end
 function rules.fieldsDefinedOnType(node, context)
   if context.objects[#context.objects] == false then
     local parent = context.objects[#context.objects - 1]
-    if(parent.__type == 'List') then
-      parent = parent.ofType
-    end
+    if parent.ofType then parent = parent.ofType end
     error('Field "' .. node.name.value .. '" is not defined on type "' .. parent.name .. '"')
   end
 end
 
 function rules.argumentsDefinedOnType(node, context)
   if node.arguments then
-    local parentField = util.getParentField(context, node.name.value)
+    local parentField = getParentField(context, node.name.value)
     for _, argument in pairs(node.arguments) do
       local name = argument.name.value
       if not parentField.arguments[name] then
@@ -178,18 +177,19 @@ end
 
 function rules.argumentsOfCorrectType(node, context)
   if node.arguments then
-    local parentField = util.getParentField(context, node.name.value)
+    local parentField = getParentField(context, node.name.value)
     for _, argument in pairs(node.arguments) do
+
       local name = argument.name.value
       local argumentType = parentField.arguments[name]
-      util.coerceValue(argument.value, argumentType)
+      util.coerceValue(argument.value, argumentType.kind or argumentType)
     end
   end
 end
 
 function rules.requiredArgumentsPresent(node, context)
   local arguments = node.arguments or {}
-  local parentField = util.getParentField(context, node.name.value)
+  local parentField = getParentField(context, node.name.value)
   for name, argument in pairs(parentField.arguments) do
     if argument.__type == 'NonNull' then
       local present = util.find(arguments, function(argument)
@@ -276,6 +276,9 @@ end
 function rules.fragmentSpreadIsPossible(node, context)
   local fragment = node.kind == 'inlineFragment' and node or context.fragmentMap[node.name.value]
   local parentType = context.objects[#context.objects - 1]
+  if parentType.ofType then parentType = parentType.ofType end
+  if parentType.ofType then parentType = parentType.ofType end
+  if parentType.ofType then parentType = parentType.ofType end
 
   local fragmentType
   if node.kind == 'inlineFragment' then
@@ -298,6 +301,8 @@ function rules.fragmentSpreadIsPossible(node, context)
         types[kind.types[i]] = kind.types[i]
       end
       return types
+    else 
+      return {}
     end
   end
 
@@ -448,7 +453,7 @@ function rules.variableUsageAllowed(node, context)
     if not arguments then return end
 
     for field in pairs(arguments) do
-      local parentField = util.getParentField(context, field)
+      local parentField = getParentField(context, field)
       for i = 1, #arguments[field] do
         local argument = arguments[field][i]
         if argument.value.kind == 'variable' then

+ 62 - 11
graphql/schema.lua

@@ -1,30 +1,32 @@
 local path = (...):gsub('%.[^%.]+$', '')
 local types = require(path .. '.types')
 
+local introspection = require(path .. '.introspection')
 local schema = {}
 schema.__index = schema
 
 function schema.create(config)
   assert(type(config.query) == 'table', 'must provide query object')
-
+  if config.mutation then
+    assert(type(config.mutation) == 'table', 'mutation must be a table')
+  end
+  if config.subscription then
+    assert(type(config.subscription) == 'table', 'subscription must be a table')
+  end
+  
   local self = {}
   for k, v in pairs(config) do
     self[k] = v
   end
 
   self.typeMap = {
-    Int = types.int,
-    Float = types.float,
-    String = types.string,
-    Boolean = types.boolean,
-    ID = types.id
   }
 
   self.interfaceMap = {}
   self.directiveMap = {}
 
   local function generateTypeMap(node)
-    if self.typeMap[node.name] and self.typeMap[node.name] == node then return end
+    if not node or (self.typeMap[node.name] and self.typeMap[node.name] == node) then return end
 
     if node.__type == 'NonNull' or node.__type == 'List' then
       return generateTypeMap(node.ofType)
@@ -34,6 +36,7 @@ function schema.create(config)
       error('Encountered multiple types named "' .. node.name .. '"')
     end
 
+    if type(node.fields) == 'function' then node.fields = node.fields() end
     self.typeMap[node.name] = node
 
     if node.__type == 'Object' and node.interfaces then
@@ -45,20 +48,26 @@ function schema.create(config)
     end
 
     if node.__type == 'Object' or node.__type == 'Interface' or node.__type == 'InputObject' then
-      if type(node.fields) == 'function' then node.fields = node.fields() end
       for fieldName, field in pairs(node.fields) do
         if field.arguments then
-          for _, argument in pairs(field.arguments) do
-            generateTypeMap(argument)
+          for k, argument in pairs(field.arguments) do
+            if argument.__type
+            then generateTypeMap(argument)
+            else
+              assert(type(argument.kind) == 'table', 'kind of argument "'.. k ..'" for "' .. fieldName .. '" must be supplied')
+              generateTypeMap(argument.kind)
+            end
           end
         end
-
         generateTypeMap(field.kind)
       end
     end
   end
 
   generateTypeMap(self.query)
+  generateTypeMap(self.mutation)
+  generateTypeMap(self.subscription)
+  generateTypeMap(introspection.__Schema)
 
   self.directives = self.directives or {
     types.include,
@@ -90,4 +99,46 @@ function schema:getDirective(name)
   return self.directiveMap[name]
 end
 
+function schema:getQueryType()
+  return self.query
+end
+
+function schema:getMutationType()
+  return self.mutation
+end
+
+function schema:getSubscriptionType()
+  return self.subscription
+end
+
+function schema:getTypeMap()
+  return self.typeMap
+end
+
+function schema:getPossibleTypes(abstractType)
+  if abstractType.__type == 'Union' then
+    return abstractType.types;
+  end
+  return self:getImplementors(abstractType);
+end
+
+
+function schema.getParentField(context, name, count)
+  local parent = nil
+  if name == '__schema' then
+    parent = introspection.SchemaMetaFieldDef
+  elseif name == '__type' then
+    parent = introspection.TypeMetaFieldDef
+  elseif name == '__typename' then
+    parent = introspection.TypeNameMetaFieldDef
+  else
+    count = count == nil and 1 or count
+    local obj = context.objects[#context.objects - count]
+    if obj.ofType then obj = obj.ofType end
+    parent = obj.fields[name]
+  end
+  return parent
+end
+
+
 return schema

+ 39 - 13
graphql/types.lua

@@ -61,6 +61,7 @@ function types.object(config)
   local instance = {
     __type = 'Object',
     name = config.name,
+    description = config.description,
     isTypeOf = config.isTypeOf,
     fields = fields,
     interfaces = config.interfaces
@@ -108,6 +109,8 @@ function initFields(kind, fields)
     result[fieldName] = {
       name = fieldName,
       kind = field.kind,
+      description = field.description,
+      deprecationReason = field.deprecationReason,
       arguments = field.arguments or {},
       resolve = kind == 'Object' and field.resolve or nil
     }
@@ -119,12 +122,26 @@ end
 function types.enum(config)
   assert(type(config.name) == 'string', 'type name must be provided as a string')
   assert(type(config.values) == 'table', 'values table must be provided')
-
+  local values = {}
+  for k, v in pairs(config.values) do
+    local val = type(v) == 'table' and v or {value = v}
+    values[k] = {
+      name = k,
+      description = val.description,
+      deprecationReason = val.deprecationReason,
+      value = val.value
+    }
+  end
   local instance = {
     __type = 'Enum',
     name = config.name,
     description = config.description,
-    values = config.values
+    serialize = function(self, v)
+      if self.values[v] then return self.values[v].value
+      else return nil
+      end
+    end,
+    values = values
   }
 
   instance.nonNull = types.nonNull(instance)
@@ -181,6 +198,7 @@ end
 
 types.int = types.scalar({
   name = 'Int',
+  description = "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1. ", 
   serialize = coerceInt,
   parseValue = coerceInt,
   parseLiteral = function(node)
@@ -203,6 +221,7 @@ types.float = types.scalar({
 
 types.string = types.scalar({
   name = 'String',
+  description = "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.",
   serialize = tostring,
   parseValue = tostring,
   parseLiteral = function(node)
@@ -218,6 +237,7 @@ end
 
 types.boolean = types.scalar({
   name = 'Boolean',
+  description = "The `Boolean` scalar type represents `true` or `false`.",
   serialize = toboolean,
   parseValue = toboolean,
   parseLiteral = function(node)
@@ -246,9 +266,13 @@ function types.directive(config)
     name = config.name,
     description = config.description,
     arguments = config.arguments,
-    onOperation = config.onOperation or false,
-    onFragment = config.onOperation or false,
-    onField = config.onField or false
+    onQuery = config.onQuery or false,
+    onMutation = config.onMutation or false,
+    onSubscription = config.onSubscription or false,
+    onField = config.onField or false,
+    onFragmentDefinition = config.onFragmentDefinition or false,
+    onFragmentSpread = config.onFragmentSpread or false,
+    onInlineFragment = config.onInlineFragment or false,
   }
 
   return instance
@@ -256,22 +280,24 @@ end
 
 types.include = types.directive({
   name = 'include',
+  description = 'Directs the executor to include this field or fragment only when the `if` argument is true.',
   arguments = {
-    ['if'] = types.boolean.nonNull
+    ['if'] = { kind = types.boolean.nonNull, description = 'Included when true.'}
   },
-  onOperation = false,
-  onFragment = true,
-  onField = true
+  onField = true,
+  onFragmentSpread = true,
+  onInlineFragment = true
 })
 
 types.skip = types.directive({
   name = 'skip',
+  description = 'Directs the executor to skip this field or fragment when the `if` argument is true.',
   arguments = {
-    ['if'] = types.boolean.nonNull
+    ['if'] = { kind = types.boolean.nonNull, description = 'Skipped when true.' }
   },
-  onOperation = false,
-  onFragment = true,
-  onField = true
+  onField = true,
+  onFragmentSpread = true,
+  onInlineFragment = true
 })
 
 return types

+ 10 - 10
graphql/util.lua

@@ -13,6 +13,16 @@ function util.find(t, fn)
   end
 end
 
+function util.filter(t, fn)
+  local res = {}
+  for k,v in pairs(t) do
+    if fn(v) then
+      table.insert(res, v)
+    end
+  end
+  return res
+end
+
 function util.compose(f, g)
   return function(...) return f(g(...)) end
 end
@@ -23,16 +33,6 @@ function util.bind1(func, x)
   end
 end
 
-function util.getParentField(context, name, count)
-  count = count == nil and 1 or count
-  local obj = context.objects[#context.objects - count]
-  if obj.__type == 'List' then
-    return obj.ofType.fields[name]
-  else
-    return obj.fields[name]
-  end
-end
-
 function util.coerceValue(node, schemaType, variables)
   variables = variables or {}
 

+ 29 - 8
graphql/validate.lua

@@ -1,6 +1,8 @@
 local path = (...):gsub('%.[^%.]+$', '')
 local rules = require(path .. '.rules')
 local util = require(path .. '.util')
+local introspection = require(path .. '.introspection')
+local getParentField = require(path .. '.schema').getParentField
 
 local visitors = {
   document = {
@@ -21,7 +23,7 @@ local visitors = {
 
   operation = {
     enter = function(node, context)
-      table.insert(context.objects, context.schema.query)
+      table.insert(context.objects, context.schema[node.operation])
       context.currentOperation = node
       context.variableReferences = {}
     end,
@@ -59,10 +61,20 @@ local visitors = {
 
   field = {
     enter = function(node, context)
-      local parentField = util.getParentField(context, node.name.value, 0)
-
-      -- false is a special value indicating that the field was not present in the type definition.
-      local field = parentField and parentField.kind or false
+      local field, parentField
+      local name = node.name.value
+      if name == '__schema' then
+        field = introspection.SchemaMetaFieldDef.kind
+      elseif name == '__type' then
+        field = introspection.TypeMetaFieldDef.kind
+      elseif name == '__typename' then
+        field = introspection.TypeNameMetaFieldDef.kind
+      else
+        parentField = getParentField(context, name, 0)
+        -- false is a special value indicating that the field was not present in the type definition.
+        field = parentField and parentField.kind or false
+      end
+      
       table.insert(context.objects, field)
     end,
 
@@ -157,9 +169,14 @@ local visitors = {
                 collectTransitiveVariables(selection)
               end
             end
-          elseif referencedNode.kind == 'field' and referencedNode.arguments then
-            for _, argument in ipairs(referencedNode.arguments) do
-              collectTransitiveVariables(argument)
+          elseif referencedNode.kind == 'field' then
+            if referencedNode.arguments then
+              for _, argument in ipairs(referencedNode.arguments) do
+                collectTransitiveVariables(argument)
+              end
+            end
+            if referencedNode.selectionSet then 
+              collectTransitiveVariables(referencedNode.selectionSet) 
             end
           elseif referencedNode.kind == 'argument' then
             return collectTransitiveVariables(referencedNode.value)
@@ -171,6 +188,7 @@ local visitors = {
             return collectTransitiveVariables(referencedNode.selectionSet)
           elseif referencedNode.kind == 'fragmentSpread' then
             local fragment = context.fragmentMap[referencedNode.name.value]
+            context.usedFragments[referencedNode.name.value] = true
             return fragment and collectTransitiveVariables(fragment.selectionSet)
           end
         end
@@ -179,6 +197,9 @@ local visitors = {
       end
     end,
 
+    exit = function(node, context)
+      table.remove(context.objects)
+    end,
     rules = {
       rules.fragmentSpreadTargetDefined,
       rules.fragmentSpreadIsPossible,

+ 0 - 0
tests/data/schema.lua → tests/data/species.lua


+ 162 - 0
tests/data/todo.lua

@@ -0,0 +1,162 @@
+local types = require 'graphql.types'
+local schema = require 'graphql.schema'
+
+local clients = {
+  [1] = { id = 1, name = "Microsoft" },
+  [2] = { id = 2, name = "Oracle'" },
+  [3] = { id = 3, name = "Apple" }
+}
+
+local projects = {
+  [1] = { id = 1, name = "Windows 7", client_id = 1 },
+  [2] = { id = 2, name = "Windows 10", client_id = 1 },
+  [3] = { id = 3, name = "IOS", client_id = 3 },
+  [4] = { id = 4, name = "OSX", client_id = 3 }
+}
+
+local tasks = {
+  [1] = { id = 1, name = "Design w7", project_id = 1 },
+  [2] = { id = 2, name = "Code w7", project_id = 1 },
+  [3] = { id = 3, name = "Unassigned Task", project_id = 1 },
+  [4] = { id = 4, name = "Design w10", project_id = 2 },
+  [5] = { id = 5, name = "Code w10", project_id = 2 },
+  [6] = { id = 6, name = "Design IOS", project_id = 3 },
+  [7] = { id = 7, name = "Code IOS", project_id = 3 },
+  [8] = { id = 8, name = "Design OSX", project_id = 4 },
+  [9] = { id = 9, name = "Code OSX", project_id = 4 }
+}
+
+local getObjectById = function(store, id)
+  return store[id]
+end
+
+local getObjectsByKey = function(store, key, value)
+  local results = {}
+  for k,v in pairs(store) do
+    if v[key] == value then
+      table.insert(results, v)
+    end
+  end
+  return results
+end
+
+local getClientById = function (id) return getObjectById(clients, id) end
+local getProjectById = function (id) return getObjectById(projects, id) end
+local getTaskById = function (id) return getObjectById(clients, id) end
+local getProjectByClientId = function (id) return getObjectsByKey(projects, "client_id") end
+local getTasksByProjectId = function (id) return getObjectsByKey(tasks, "project_id") end
+
+
+local project, client, task
+client = types.object {
+  name = 'Client',
+  description = 'Client',
+  fields = function()
+    return {
+      id = { kind = types.nonNull(types.int), description = 'The id of the client.'},
+      name = { kind = types.string, description = 'The name of the client.'},
+      projects = {
+        kind = types.list(project),
+        description = 'projects',
+        resolve = function(client, arguments)
+          return getProjectByClientId(client.id)
+        end
+      }
+    }
+  end
+}
+
+project = types.object {
+  name = 'Project',
+  description = 'Project',
+  fields = function()
+    return {
+      id = { kind = types.nonNull(types.int), description = 'The id of the project.'},
+      name = { kind = types.string, description = 'The name of the project.'},
+      client_id = { kind = types.nonNull(types.int), description = 'client id'},
+      client = {
+        kind = client,
+        description = 'client',
+        resolve = function(project)
+          return getClientById(project.client_id)
+        end
+      },
+      tasks = {
+        kind = types.list(task),
+        description = 'tasks',
+        resolve = function(project, arguments)
+          return getTasksByProjectId(project.id)
+        end
+      }
+    }
+  end
+}
+
+task = types.object {
+  name = 'Task',
+  description = 'Task',
+  fields = function()
+    return {
+      id = { kind = types.nonNull(types.int), description = 'The id of the task.'},
+      name = { kind = types.string, description = 'The name of the task.'},
+      project_id = { kind = types.nonNull(types.int), description = 'project id'},
+      project = {
+        kind = project,
+        description = 'project',
+        resolve = function(task)
+          return getProjectById(task.project_id)
+        end
+      }
+    }
+  end
+}
+
+
+-- Create a schema
+return schema.create {
+  query = types.object {
+    name = 'Query',
+    fields = {
+      client = {
+        kind = client,
+        arguments = {
+          id = {
+            kind = types.nonNull(types.int),
+            description = 'id of the client'
+          }
+        },
+        resolve = function(rootValue, arguments)
+          return getClientById(arguments.id)
+        end
+      },
+
+      project = {
+        kind = project,
+        arguments = {
+          id = {
+            kind = types.nonNull(types.int),
+            description = 'id of the project'
+          }
+
+        },
+        resolve = function(rootValue, arguments)
+          return getProjectById(arguments.id)
+        end
+      },
+
+      task = {
+        kind = task,
+        arguments = {
+          id = {
+            kind = types.nonNull(types.int),
+            description = 'id of the task'
+          }
+
+        },
+        resolve = function(rootValue, arguments)
+          return getTaskById(arguments.id)
+        end
+      }
+    }
+  }
+}

+ 1333 - 0
tests/introspection.lua

@@ -0,0 +1,1333 @@
+local parse = require 'graphql.parse'
+local validate = require 'graphql.validate'
+local execute = require 'graphql.execute'
+local util = require 'graphql.util'
+local cjson = require 'cjson'
+local schema = require 'tests/data/todo'
+
+
+local introspection_query = [[
+  query IntrospectionQuery {
+    __schema {
+      queryType { name }
+      mutationType { name }
+      subscriptionType { name }
+      types {
+        ...FullType
+      }
+      directives {
+        name
+        description
+        locations
+        args {
+          ...InputValue
+        }
+      }
+    }
+  }
+
+  fragment FullType on __Type {
+    kind
+    name
+    description
+    fields(includeDeprecated: true) {
+      name
+      description
+      args {
+        ...InputValue
+      }
+      type {
+        ...TypeRef
+      }
+      isDeprecated
+      deprecationReason
+    }
+    inputFields {
+      ...InputValue
+    }
+    interfaces {
+      ...TypeRef
+    }
+    enumValues(includeDeprecated: true) {
+      name
+      description
+      isDeprecated
+      deprecationReason
+    }
+    possibleTypes {
+      ...TypeRef
+    }
+  }
+
+  fragment InputValue on __InputValue {
+    name
+    description
+    type { ...TypeRef }
+    defaultValue
+  }
+
+  fragment TypeRef on __Type {
+    kind
+    name
+    ofType {
+      kind
+      name
+      ofType {
+        kind
+        name
+        ofType {
+          kind
+          name
+          ofType {
+            kind
+            name
+            ofType {
+              kind
+              name
+              ofType {
+                kind
+                name
+                ofType {
+                  kind
+                  name
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+]]
+local introspection_expected_json = [[
+  {
+    "__schema": {
+      "directives": [
+        {
+          "args": [
+            {
+              "defaultValue": null,
+              "description": "Included when true.",
+              "name": "if",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            }
+          ],
+          "description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
+          "locations": [
+            "FIELD",
+            "FRAGMENT_SPREAD",
+            "INLINE_FRAGMENT"
+          ],
+          "name": "include"
+        },
+        {
+          "args": [
+            {
+              "defaultValue": null,
+              "description": "Skipped when true.",
+              "name": "if",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            }
+          ],
+          "description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
+          "locations": [
+            "FIELD",
+            "FRAGMENT_SPREAD",
+            "INLINE_FRAGMENT"
+          ],
+          "name": "skip"
+        }
+      ],
+      "mutationType": null,
+      "queryType": {
+        "name": "Query"
+      },
+      "subscriptionType": null,
+      "types": [
+        {
+          "description": null,
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [
+                {
+                  "defaultValue": null,
+                  "description": "id of the client",
+                  "name": "id",
+                  "type": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "SCALAR",
+                      "name": "Int",
+                      "ofType": null
+                    }
+                  }
+                }
+              ],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "client",
+              "type": {
+                "kind": "OBJECT",
+                "name": "Client",
+                "ofType": null
+              }
+            },
+            {
+              "args": [
+                {
+                  "defaultValue": null,
+                  "description": "id of the project",
+                  "name": "id",
+                  "type": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "SCALAR",
+                      "name": "Int",
+                      "ofType": null
+                    }
+                  }
+                }
+              ],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "project",
+              "type": {
+                "kind": "OBJECT",
+                "name": "Project",
+                "ofType": null
+              }
+            },
+            {
+              "args": [
+                {
+                  "defaultValue": null,
+                  "description": "id of the task",
+                  "name": "id",
+                  "type": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "SCALAR",
+                      "name": "Int",
+                      "ofType": null
+                    }
+                  }
+                }
+              ],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "task",
+              "type": {
+                "kind": "OBJECT",
+                "name": "Task",
+                "ofType": null
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "Query",
+          "possibleTypes": null
+        },
+        {
+          "description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1. ",
+          "enumValues": null,
+          "fields": null,
+          "inputFields": null,
+          "interfaces": null,
+          "kind": "SCALAR",
+          "name": "Int",
+          "possibleTypes": null
+        },
+        {
+          "description": "Client",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The id of the client.",
+              "isDeprecated": false,
+              "name": "id",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Int",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The name of the client.",
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "projects",
+              "isDeprecated": false,
+              "name": "projects",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "OBJECT",
+                  "name": "Project",
+                  "ofType": null
+                }
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "Client",
+          "possibleTypes": null
+        },
+        {
+          "description": "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.",
+          "enumValues": null,
+          "fields": null,
+          "inputFields": null,
+          "interfaces": null,
+          "kind": "SCALAR",
+          "name": "String",
+          "possibleTypes": null
+        },
+        {
+          "description": "Project",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The id of the project.",
+              "isDeprecated": false,
+              "name": "id",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Int",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The name of the project.",
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "client id",
+              "isDeprecated": false,
+              "name": "client_id",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Int",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "client",
+              "isDeprecated": false,
+              "name": "client",
+              "type": {
+                "kind": "OBJECT",
+                "name": "Client",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "tasks",
+              "isDeprecated": false,
+              "name": "tasks",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "OBJECT",
+                  "name": "Task",
+                  "ofType": null
+                }
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "Project",
+          "possibleTypes": null
+        },
+        {
+          "description": "Task",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The id of the task.",
+              "isDeprecated": false,
+              "name": "id",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Int",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The name of the task.",
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "project id",
+              "isDeprecated": false,
+              "name": "project_id",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Int",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "project",
+              "isDeprecated": false,
+              "name": "project",
+              "type": {
+                "kind": "OBJECT",
+                "name": "Project",
+                "ofType": null
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "Task",
+          "possibleTypes": null
+        },
+        {
+          "description": "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "A list of all types supported by this server.",
+              "isDeprecated": false,
+              "name": "types",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "LIST",
+                  "name": null,
+                  "ofType": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "OBJECT",
+                      "name": "__Type",
+                      "ofType": null
+                    }
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "The type that query operations will be rooted at.",
+              "isDeprecated": false,
+              "name": "queryType",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "OBJECT",
+                  "name": "__Type",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "If this server supports mutation, the type that mutation operations will be rooted at.",
+              "isDeprecated": false,
+              "name": "mutationType",
+              "type": {
+                "kind": "OBJECT",
+                "name": "__Type",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "If this server support subscription, the type that subscription operations will be rooted at.",
+              "isDeprecated": false,
+              "name": "subscriptionType",
+              "type": {
+                "kind": "OBJECT",
+                "name": "__Type",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "A list of all directives supported by this server.",
+              "isDeprecated": false,
+              "name": "directives",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "LIST",
+                  "name": null,
+                  "ofType": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "OBJECT",
+                      "name": "__Directive",
+                      "ofType": null
+                    }
+                  }
+                }
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "__Schema",
+          "possibleTypes": null
+        },
+        {
+          "description": "The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.\n\nDepending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name and description, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "kind",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "ENUM",
+                  "name": "__TypeKind",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "description",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [
+                {
+                  "defaultValue": "false",
+                  "description": null,
+                  "name": "includeDeprecated",
+                  "type": {
+                    "kind": "SCALAR",
+                    "name": "Boolean",
+                    "ofType": null
+                  }
+                }
+              ],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "fields",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "NON_NULL",
+                  "name": null,
+                  "ofType": {
+                    "kind": "OBJECT",
+                    "name": "__Field",
+                    "ofType": null
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "interfaces",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "NON_NULL",
+                  "name": null,
+                  "ofType": {
+                    "kind": "OBJECT",
+                    "name": "__Type",
+                    "ofType": null
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "possibleTypes",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "NON_NULL",
+                  "name": null,
+                  "ofType": {
+                    "kind": "OBJECT",
+                    "name": "__Type",
+                    "ofType": null
+                  }
+                }
+              }
+            },
+            {
+              "args": [
+                {
+                  "defaultValue": "false",
+                  "description": null,
+                  "name": "includeDeprecated",
+                  "type": {
+                    "kind": "SCALAR",
+                    "name": "Boolean",
+                    "ofType": null
+                  }
+                }
+              ],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "enumValues",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "NON_NULL",
+                  "name": null,
+                  "ofType": {
+                    "kind": "OBJECT",
+                    "name": "__EnumValue",
+                    "ofType": null
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "inputFields",
+              "type": {
+                "kind": "LIST",
+                "name": null,
+                "ofType": {
+                  "kind": "NON_NULL",
+                  "name": null,
+                  "ofType": {
+                    "kind": "OBJECT",
+                    "name": "__InputValue",
+                    "ofType": null
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "ofType",
+              "type": {
+                "kind": "OBJECT",
+                "name": "__Type",
+                "ofType": null
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "__Type",
+          "possibleTypes": null
+        },
+        {
+          "description": "An enum describing what kind of type a given `__Type` is.",
+          "enumValues": [
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is a scalar.",
+              "isDeprecated": false,
+              "name": "SCALAR"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is an object. `fields` and `interfaces` are valid fields.",
+              "isDeprecated": false,
+              "name": "OBJECT"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.",
+              "isDeprecated": false,
+              "name": "INTERFACE"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is a union. `possibleTypes` is a valid field.",
+              "isDeprecated": false,
+              "name": "UNION"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is an enum. `enumValues` is a valid field.",
+              "isDeprecated": false,
+              "name": "ENUM"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is an input object. `inputFields` is a valid field.",
+              "isDeprecated": false,
+              "name": "INPUT_OBJECT"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is a list. `ofType` is a valid field.",
+              "isDeprecated": false,
+              "name": "LIST"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Indicates this type is a non-null. `ofType` is a valid field.",
+              "isDeprecated": false,
+              "name": "NON_NULL"
+            }
+          ],
+          "fields": null,
+          "inputFields": null,
+          "interfaces": null,
+          "kind": "ENUM",
+          "name": "__TypeKind",
+          "possibleTypes": null
+        },
+        {
+          "description": "The `Boolean` scalar type represents `true` or `false`.",
+          "enumValues": null,
+          "fields": null,
+          "inputFields": null,
+          "interfaces": null,
+          "kind": "SCALAR",
+          "name": "Boolean",
+          "possibleTypes": null
+        },
+        {
+          "description": "Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "String",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "description",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "args",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "LIST",
+                  "name": null,
+                  "ofType": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "OBJECT",
+                      "name": "__InputValue",
+                      "ofType": null
+                    }
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "type",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "OBJECT",
+                  "name": "__Type",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "isDeprecated",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "deprecationReason",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "__Field",
+          "possibleTypes": null
+        },
+        {
+          "description": "Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "String",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "description",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "type",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "OBJECT",
+                  "name": "__Type",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": "A GraphQL-formatted string representing the default value for this input value.",
+              "isDeprecated": false,
+              "name": "defaultValue",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "__InputValue",
+          "possibleTypes": null
+        },
+        {
+          "description": "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "String",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "description",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "isDeprecated",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "deprecationReason",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "__EnumValue",
+          "possibleTypes": null
+        },
+        {
+          "description": "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.\n\nIn some cases, you need to provide options to alter GraphQL’s execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.",
+          "enumValues": null,
+          "fields": [
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "name",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "String",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "description",
+              "type": {
+                "kind": "SCALAR",
+                "name": "String",
+                "ofType": null
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "locations",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "LIST",
+                  "name": null,
+                  "ofType": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "ENUM",
+                      "name": "__DirectiveLocation",
+                      "ofType": null
+                    }
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": null,
+              "description": null,
+              "isDeprecated": false,
+              "name": "args",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "LIST",
+                  "name": null,
+                  "ofType": {
+                    "kind": "NON_NULL",
+                    "name": null,
+                    "ofType": {
+                      "kind": "OBJECT",
+                      "name": "__InputValue",
+                      "ofType": null
+                    }
+                  }
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": "Use `locations`.",
+              "description": null,
+              "isDeprecated": true,
+              "name": "onOperation",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": "Use `locations`.",
+              "description": null,
+              "isDeprecated": true,
+              "name": "onFragment",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            },
+            {
+              "args": [],
+              "deprecationReason": "Use `locations`.",
+              "description": null,
+              "isDeprecated": true,
+              "name": "onField",
+              "type": {
+                "kind": "NON_NULL",
+                "name": null,
+                "ofType": {
+                  "kind": "SCALAR",
+                  "name": "Boolean",
+                  "ofType": null
+                }
+              }
+            }
+          ],
+          "inputFields": null,
+          "interfaces": [],
+          "kind": "OBJECT",
+          "name": "__Directive",
+          "possibleTypes": null
+        },
+        {
+          "description": "A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.",
+          "enumValues": [
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to a query operation.",
+              "isDeprecated": false,
+              "name": "QUERY"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to a mutation operation.",
+              "isDeprecated": false,
+              "name": "MUTATION"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to a subscription operation.",
+              "isDeprecated": false,
+              "name": "SUBSCRIPTION"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to a field.",
+              "isDeprecated": false,
+              "name": "FIELD"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to a fragment definition.",
+              "isDeprecated": false,
+              "name": "FRAGMENT_DEFINITION"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to a fragment spread.",
+              "isDeprecated": false,
+              "name": "FRAGMENT_SPREAD"
+            },
+            {
+              "deprecationReason": null,
+              "description": "Location adjacent to an inline fragment.",
+              "isDeprecated": false,
+              "name": "INLINE_FRAGMENT"
+            }
+          ],
+          "fields": null,
+          "inputFields": null,
+          "interfaces": null,
+          "kind": "ENUM",
+          "name": "__DirectiveLocation",
+          "possibleTypes": null
+        }
+      ]
+    }
+  }
+]]
+
+describe('introspection', function()
+  local rootValue = {}
+  local variables = {}
+  local operationName = 'IntrospectionQuery'
+  local response = execute(schema, parse(introspection_query), rootValue, variables, operationName)
+  local expected = cjson.decode(introspection_expected_json)
+  assert:set_parameter("TableFormatLevel", 10) 
+  local compare_by_name = function(a,b) return a.name < b.name end  
+  table.sort(response.__schema.directives, compare_by_name)
+  table.sort(expected.__schema.directives, compare_by_name)
+  table.sort(response.__schema.types, compare_by_name)
+  table.sort(expected.__schema.types, compare_by_name)
+  for i,v in ipairs(expected.__schema.types) do
+    if v.fields ~= cjson.null then table.sort(v.fields, compare_by_name) end
+    if v.enumValues ~= cjson.null then table.sort(v.enumValues, compare_by_name) end
+  end
+  for i,v in ipairs(response.__schema.types) do
+    if v.fields ~= cjson.null then table.sort(v.fields, compare_by_name) end
+    if v.enumValues ~= cjson.null then table.sort(v.enumValues, compare_by_name) end
+  end
+  
+  it('basic json equality test', function()
+      assert.are.same(cjson.decode('{"a":1,    "b":2}'),{b = 2, a = 1})
+  end)
+  
+  it('root nodes are set', function()
+      assert.is.truthy(response.__schema)
+      assert.is.truthy(response.__schema.directives)
+      assert.is.truthy(response.__schema.mutationType)
+      assert.is.truthy(response.__schema.queryType)
+      assert.is.truthy(response.__schema.subscriptionType)
+      assert.is.truthy(response.__schema.types)
+  end)
+
+  it('mutationType match', function()
+    assert.are.same(expected.__schema.mutationType, response.__schema.mutationType)
+  end)
+  
+  it('queryType match', function()
+    assert.are.same(expected.__schema.queryType, response.__schema.queryType)
+  end)
+
+  it('subscriptionType match', function()
+    assert.are.same(expected.__schema.subscriptionType, response.__schema.subscriptionType)
+  end)
+
+  it('root types are same', function()
+    local expected = util.map(expected.__schema.types, function ( t ) return t.name end)
+    local response = util.map(response.__schema.types, function ( t ) return t.name end)
+    table.sort(expected)
+    table.sort(response)
+    assert.are.same(expected, response)
+  end)
+
+  it('types match', function()
+    assert.are.same(expected.__schema.types, response.__schema.types)
+  end)
+
+  it('directives match', function()
+    assert.are.same(expected.__schema.directives, response.__schema.directives)
+  end)
+
+  it('all match', function()
+    assert.are.same(expected, response)
+  end)
+
+end)

+ 1 - 1
tests/rules.lua

@@ -1,6 +1,6 @@
 local parse = require 'graphql.parse'
 local validate = require 'graphql.validate'
-local schema = require 'tests/data/schema'
+local schema = require 'tests/data/species'
 
 local function expectError(message, document)
   if not message then

+ 1 - 0
tests/runner.lua

@@ -5,6 +5,7 @@ for _, fn in pairs({'describe', 'it', 'test', 'expect', 'spy', 'before', 'after'
 end
 
 local files = {
+  -- 'introspection', use busted
   'parse',
   'rules'
 }