Vincit / objection-graphql

GraphQL schema generator for objection.js
MIT License
307 stars 34 forks source link

Can someone help me setting up graphql with this lib? #50

Closed e200 closed 6 years ago

e200 commented 6 years ago

I'm following the readme example with my already created model:

const Model = require('../model')

class File extends Model {
  static get tableName()
  {
    return 'files'
  }

  static jsonSchema()
  {
    return {
      type: 'object',
      require: ['name'],
      properties: {
        id: { type: 'integer' },
        name: { type: 'string' },
        path: { type: 'string' },
        description: { type: 'string' }
      }
    }
  }
}

module.exports = File

This is how I'm setting up the GraphQL:

const { builder } = require('objection-graphql')
const graphql = require('express-graphql')
const file = require('../models/file')

const schema = builder()
          .model(file)
          .build()

        app.use('/graphql', graphql({
          schema: schema,
          graphiql: true
        }))

When I run this on graphiQL:

{
  Files(orderBy: id) {
    name
  }
}

this is what I got:

{
  "errors": [
    {
      "message": "Enum type FilesPropertiesEnum must define one or more values.\n\nType Files must define one or more fields."
    }
  ]
}

What I'm doing wrong?