Explorar el Código

More introspection cleanup;

bjorn hace 9 años
padre
commit
16936cf265
Se han modificado 11 ficheros con 109 adiciones y 1585 borrados
  1. 3 17
      graphql/execute.lua
  2. 6 1
      graphql/introspection.lua
  3. 16 2
      graphql/rules.lua
  4. 43 65
      graphql/schema.lua
  5. 17 14
      graphql/types.lua
  6. 23 14
      graphql/validate.lua
  7. 0 0
      tests/data/schema.lua
  8. 0 162
      tests/data/todo.lua
  9. 0 1308
      tests/introspection.lua
  10. 1 1
      tests/rules.lua
  11. 0 1
      tests/runner.lua

+ 3 - 17
graphql/execute.lua

@@ -178,12 +178,9 @@ local function completeValue(fieldType, result, subSelections, context)
     return values
   end
 
-  if fieldTypeName == 'Scalar' then
+  if fieldTypeName == 'Scalar' or fieldTypeName == 'Enum' 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)
@@ -199,17 +196,7 @@ local function getFieldEntry(objectType, object, fields, context)
   local firstField = fields[1]
   local fieldName = firstField.name.value
   local responseKey = getFieldResponseKey(firstField)
-  local fieldType
-
-  if fieldName == '__schema' then
-    fieldType = introspection.Schema
-  elseif fieldName == '__type' then
-    fieldType = introspection.Type
-  elseif fieldName == '__typename' then
-    fieldType = introspection.TypeName
-  else
-    fieldType = objectType.fields[fieldName]
-  end
+  local fieldType = introspection.fieldMap[fieldName] or objectType.fields[fieldName]
 
   if fieldType == nil then
     return nil
@@ -247,8 +234,7 @@ evaluateSelections = function(objectType, object, selections, context)
   local groupedFieldSet = collectFields(objectType, selections, {}, {}, context)
 
   return util.map(groupedFieldSet, function(fields)
-    local v = getFieldEntry(objectType, object, fields, context)
-    if v ~= nil then return v else return nil end
+    return getFieldEntry(objectType, object, fields, context)
   end)
 end
 

+ 6 - 1
graphql/introspection.lua

@@ -471,5 +471,10 @@ return {
   __TypeKind = __TypeKind,
   Schema = Schema,
   Type = Type,
-  TypeName = TypeName
+  TypeName = TypeName,
+  fieldMap = {
+    __schema = Schema,
+    __type = Type,
+    __typename = TypeName
+  }
 }

+ 16 - 2
graphql/rules.lua

@@ -1,8 +1,23 @@
 local path = (...):gsub('%.[^%.]+$', '')
 local types = require(path .. '.types')
 local util = require(path .. '.util')
+local schema = require(path .. '.schema')
+local introspection = require(path .. '.introspection')
+
+local function getParentField(context, name, count)
+  if introspection.fieldMap[name] then return introspection.fieldMap[name] end
+
+  count = count or 1
+  local parent = context.objects[#context.objects - count]
+
+  -- Unwrap lists and non-null types
+  while parent.ofType do
+    parent = parent.ofType
+  end
+
+  return parent.fields[name]
+end
 
-local getParentField = require(path .. '.schema').getParentField
 local rules = {}
 
 function rules.uniqueOperationNames(node, context)
@@ -179,7 +194,6 @@ function rules.argumentsOfCorrectType(node, context)
   if node.arguments then
     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.kind or argumentType)

+ 43 - 65
graphql/schema.lua

@@ -1,7 +1,7 @@
 local path = (...):gsub('%.[^%.]+$', '')
 local types = require(path .. '.types')
-
 local introspection = require(path .. '.introspection')
+
 local schema = {}
 schema.__index = schema
 
@@ -15,66 +15,64 @@ function schema.create(config)
     self[k] = v
   end
 
-  self.typeMap = {}
+  self.directives = self.directives or {
+    types.include,
+    types.skip
+  }
 
+  self.typeMap = {}
   self.interfaceMap = {}
   self.directiveMap = {}
 
-  local function generateTypeMap(node)
-    if not node or (self.typeMap[node.name] and self.typeMap[node.name] == node) then return end
+  self:generateTypeMap(self.query)
+  self:generateTypeMap(self.mutation)
+  self:generateTypeMap(introspection.__Schema)
+  self:generateDirectiveMap()
 
-    if node.__type == 'NonNull' or node.__type == 'List' then
-      return generateTypeMap(node.ofType)
-    end
+  return self
+end
 
-    if self.typeMap[node.name] and self.typeMap[node.name] ~= node then
-      error('Encountered multiple types named "' .. node.name .. '"')
-    end
+function schema:generateTypeMap(node)
+  if not node or (self.typeMap[node.name] and self.typeMap[node.name] == node) then return end
 
-    if type(node.fields) == 'function' then node.fields = node.fields() end
-    self.typeMap[node.name] = node
+  if node.__type == 'NonNull' or node.__type == 'List' then
+    return self:generateTypeMap(node.ofType)
+  end
 
-    if node.__type == 'Object' and node.interfaces then
-      for _, interface in ipairs(node.interfaces) do
-        generateTypeMap(interface)
-        self.interfaceMap[interface.name] = self.interfaceMap[interface.name] or {}
-        self.interfaceMap[interface.name][node] = node
-      end
-    end
+  if self.typeMap[node.name] and self.typeMap[node.name] ~= node then
+    error('Encountered multiple types named "' .. node.name .. '"')
+  end
 
-    if node.__type == 'Object' or node.__type == 'Interface' or node.__type == 'InputObject' then
-      for fieldName, field in pairs(node.fields) do
-        if field.arguments then
-          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
+  node.fields = type(node.fields) == 'function' and node.fields() or node.fields
+  self.typeMap[node.name] = node
+
+  if node.__type == 'Object' and node.interfaces then
+    for _, interface in ipairs(node.interfaces) do
+      self:generateTypeMap(interface)
+      self.interfaceMap[interface.name] = self.interfaceMap[interface.name] or {}
+      self.interfaceMap[interface.name][node] = node
     end
   end
 
-  generateTypeMap(self.query)
-  generateTypeMap(self.mutation)
-  generateTypeMap(introspection.__Schema)
-
-  self.directives = self.directives or {
-    types.include,
-    types.skip
-  }
+  if node.__type == 'Object' or node.__type == 'Interface' or node.__type == 'InputObject' then
+    for fieldName, field in pairs(node.fields) do
+      if field.arguments then
+        for name, argument in pairs(field.arguments) do
+          local argumentType = argument.__type and argument or argument.kind
+          assert(argumentType, 'Must supply type for argument "' .. name .. '" on "' .. fieldName .. '"')
+          self:generateTypeMap(argumentType)
+        end
+      end
 
-  if self.directives then
-    for _, directive in ipairs(self.directives) do
-      self.directiveMap[directive.name] = directive
+      self:generateTypeMap(field.kind)
     end
   end
+end
 
-  return self
+function schema:generateDirectiveMap()
+  for _, directive in ipairs(self.directives) do
+    self.directiveMap[directive.name] = directive
+  end
 end
 
 function schema:getType(name)
@@ -113,24 +111,4 @@ function schema:getPossibleTypes(abstractType)
   return self:getImplementors(abstractType)
 end
 
-function schema.getParentField(context, name, count)
-  if name == '__schema' then
-    return introspection.Schema
-  elseif name == '__type' then
-    return introspection.Type
-  elseif name == '__typename' then
-    return introspection.TypeName
-  end
-
-  count = count or 1
-  local parent = context.objects[#context.objects - count]
-
-  -- Unwrap lists and non-null types
-  while parent.ofType do
-    parent = parent.ofType
-  end
-
-  return parent.fields[name]
-end
-
 return schema

+ 17 - 14
graphql/types.lua

@@ -122,26 +122,29 @@ 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 instance
   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
+
+  for name, entry in pairs(config.values) do
+    entry = type(entry) == 'table' and entry or { value = entry }
+
+    values[name] = {
+      name = name,
+      description = entry.description,
+      deprecationReason = entry.deprecationReason,
+      value = entry.value
     }
   end
-  local instance = {
+
+  instance = {
     __type = 'Enum',
     name = config.name,
     description = config.description,
-    serialize = function(self, v)
-      if self.values[v] then return self.values[v].value
-      else return nil
-      end
-    end,
-    values = values
+    values = values,
+    serialize = function(name)
+      return instance.values[name] and instance.values[name].value or name
+    end
   }
 
   instance.nonNull = types.nonNull(instance)

+ 23 - 14
graphql/validate.lua

@@ -2,7 +2,21 @@ 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 schema = require(path .. '.schema')
+
+local function getParentField(context, name, count)
+  if introspection.fieldMap[name] then return introspection.fieldMap[name] end
+
+  count = count or 1
+  local parent = context.objects[#context.objects - count]
+
+  -- Unwrap lists and non-null types
+  while parent.ofType do
+    parent = parent.ofType
+  end
+
+  return parent.fields[name]
+end
 
 local visitors = {
   document = {
@@ -61,22 +75,15 @@ local visitors = {
 
   field = {
     enter = function(node, context)
-      local field, parentField
       local name = node.name.value
 
-      if name == '__schema' then
-        field = introspection.Schema.kind
-      elseif name == '__type' then
-        field = introspection.Type.kind
-      elseif name == '__typename' then
-        field = introspection.TypeName.kind
+      if introspection.fieldMap[name] then
+        table.insert(context.objects, introspection.fieldMap[name].kind)
       else
-        parentField = getParentField(context, name, 0)
+        local 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
+        table.insert(context.objects, parentField and parentField.kind or false)
       end
-
-      table.insert(context.objects, field)
     end,
 
     exit = function(node, context)
@@ -176,8 +183,9 @@ local visitors = {
                 collectTransitiveVariables(argument)
               end
             end
-            if referencedNode.selectionSet then 
-              collectTransitiveVariables(referencedNode.selectionSet) 
+
+            if referencedNode.selectionSet then
+              collectTransitiveVariables(referencedNode.selectionSet)
             end
           elseif referencedNode.kind == 'argument' then
             return collectTransitiveVariables(referencedNode.value)
@@ -201,6 +209,7 @@ local visitors = {
     exit = function(node, context)
       table.remove(context.objects)
     end,
+
     rules = {
       rules.fragmentSpreadTargetDefined,
       rules.fragmentSpreadIsPossible,

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


+ 0 - 162
tests/data/todo.lua

@@ -1,162 +0,0 @@
-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
-      }
-    }
-  }
-}

+ 0 - 1308
tests/introspection.lua

@@ -1,1308 +0,0 @@
-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 }
-      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"
-      },
-      "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 and mutation 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": "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 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.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('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/species'
+local schema = require 'tests/data/schema'
 
 local function expectError(message, document)
   if not message then

+ 0 - 1
tests/runner.lua

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