Giter Club home page Giter Club logo

graphql-lua's People

Contributors

bjornbytes avatar gitter-badger avatar ruslantalpa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-lua's Issues

defaultTypeResolveFn missing

(adding this to keep track of bug discovered)
schema/execute modules need to fix how interfaces/unions are defined and executed.
Either check that the resolveType is defined or provide a default resolver and check that all underlying types implement isTypeOf function.

How to define fields of type.list with custom resolver

Project = types.object {
  name = 'Project',
  fields = function()
    return {
      id = types.id.nonNull,
      name = types.string.nonNull,
      client_id = types.id.nonNull,
      client = { -- resolver works
        kind = Client,
        resolve = function(project)
          return getClientById(project.client_id)
        end
      }
      tasks = { -- this fails
        kind = types.list(Tasks),
        resolve = function(project, arguments)
          return getTasksByProjectId(project.id)
        end
      }
    }
  end
}

it fails with validate.lua:61: attempt to index field 'fields' (a nil value) the line number might be wrong since i made a few changes

Is this the right place to fix this (accept custom resolver) or is it somewhere else?
Hints/help welcome :)

empty args for Introspection Query

Hello. I am trying to render json based on executed schema and it works almost perfect.
I noticed that even if i declare args/arguments for a field - it doesn't produce any effect on executed schema.
I have tested it also on yours test example of schema.
there is a query

-- prebuilt query
local ast = parse [[
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
              }
            }
          }
        }
      }
    }
  }
}
]]

-- Get variables
local variables = {}
-- get operation name
local operationName = 'IntrospectionQuery'

-- Validate a parsed query against a schema
local isValid = validate(schema, ast)

-- Execution
local rootValue = {}
local result = execute(schema, ast, rootValue, variables, operationName)

this query is built by graphiql by default.
so, usually then i use cjson of openresty

local json = cjson.encode(result)
-- json = string.gsub(json, '"interfaces":{},', '"interfaces":[],')
-- json = string.gsub(json, '"args":{},', '"args":[],')
ngx.say(json)

but also i've tried to pritn that table in console using print_r method from this article

Could you advice me where i could be wrong or how i could fix that behavior?
Thank you.

Kong integration

Show me a sample integrating KONG API management server and you'll have a fan and possible business partner for life!

Handling empty tables as objects or lists

@bjornbytes Thank you for merging my previous PRs. Before I send my next one, I wanted to discuss it with you (copying my comment into this issue from gitter).

The essential problem is that whatever JSON serialization library you use has to be able to distinguish between empty Lists and Objects as intended by GraphQL. Because Lua uses the same type, tables, for this purpose, it is non-obvious which one to emit. In our internal fork, we have patched graphql-lua to require resty.libcjson, which lets you set the metatable to indicate which type it should be in the output. If this is an acceptable dependency for you, I'll send the PR right away. Otherwise, I'd love to hear your thoughts on the matter.

How to define types with circular references

Can you please provide an example of how to define two types that reference each other?
For example

local Client = types.object {
  name = 'Client',
  fields = {
    id = types.id.nonNull,
    name = types.string.nonNull,
    -- projects = ...
  }
}

local Project = types.object {
  name = 'Project',
  fields = {
    id = types.id.nonNull,
    name = types.string.nonNull,
    client_id = types.id.nonNull
    --client = ...
    --tasks = ...
  }
}

local Task = types.object {
  name = 'Task',
  fields = {
    id = types.id.nonNull,
    name = types.string.nonNull,
    project_id = types.id.nonNull
    --project = ...
  }
}

If you have time and it's not too time consuming, a complete example of a schema based on these types and resolvers for them (in memory arrays) would help a lot.

The goal is to be able to issue queries like these

{
  client (id: 1) {
    id
    name
    projects {
      id
      name
      tasks {
        id
        name
      }
    }
  }
  project (id: 1) {
    id
    name
    client {
      id
      name
    }
    tasks {
      id
      name
    }
  }
}

Thank you for contributing this lib to open source, once i get a deeper understanding of the code i hope contribute back

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.