Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example doesn't work #15

Closed
fennecbutt opened this issue Feb 8, 2019 · 5 comments · Fixed by #23
Closed

Example doesn't work #15

fennecbutt opened this issue Feb 8, 2019 · 5 comments · Fixed by #23

Comments

@fennecbutt
Copy link

The example in the README doesn't work with the error: Error: Unknown directive "constraint".

As far as I can tell the directive returns its own definition, it shouldn't need to be defined in the graphql schema, right?

I've created a file containing only the js from the readme with the various imports installed, still get this error.

@fennecbutt
Copy link
Author

I've just found that this is because of a breaking change in graphql 14 mentioned here: ardatan/graphql-tools#957

Now we have to manually define custom directives in our schema...

@luismaldonadov
Copy link

I dont know if your problem is exactly like mine, but when working in custom directives for example

extend type Query { me: String! @requireAuth user(userId: ID!): User! users: [User]! }

With the graphql-tools update , the definition of the directive is needed within the schema, something like this

directive @requireAuth on FIELD_DEFINITION

Also i removed the direct dependency of graphql-tools because of the issue you referenced.

Hope this helps.

@anhldbk
Copy link

anhldbk commented Apr 3, 2019

I've got the same problem

@BrenoMazieiro
Copy link

BrenoMazieiro commented Apr 30, 2019

const ConstraintDirective = require('graphql-constraint-directive')
const express = require('express')
const bodyParser = require('body-parser')
const { graphqlExpress } = require('apollo-server-express')
const { makeExecutableSchema } = require('graphql-tools')
const typeDefs = `
  directive @constraint(
    # String constraints
    minLength: Int
    maxLength: Int
    startsWith: String
    endsWith: String
    notContains: String
    pattern: String
    format: String

    # Number constraints
    min: Int
    max: Int
    exclusiveMin: Int
    exclusiveMax: Int
    multipleOf: Int
  ) on INPUT_FIELD_DEFINITION

  type Query {
    books: [Book]
  }
  type Book {
    title: String
  }
  type Mutation {
    createBook(input: BookInput): Book
  }
  input BookInput {
    title: String! @constraint(minLength: 5, format: "email")
  }
  scalar ConstraintString
  scalar ConstraintNumber
`
const schema = makeExecutableSchema({
  typeDefs, schemaDirectives: { constraint: ConstraintDirective }
})
const app = express()

app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))

@rimiti
Copy link

rimiti commented Jul 20, 2019

Some problem.

schmidsi added a commit to schmidsi/graphql-constraint-directive that referenced this issue Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants