Giter Club home page Giter Club logo

adonis-graphql's People

Contributors

ahmadarif avatar alanaasmaa avatar andruu avatar evald24 avatar romainlanz avatar targos avatar travis-r6s avatar vinicius-batista avatar xstoudi 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

adonis-graphql's Issues

Error: Specified query type "Query" not found in document.

Error: Specified query type "Query" not found in document.

at /Users/alexandre/projects/meusclientes/start/routes.js(anonymous):17
12  | http://adonisjs.com/docs/4.1/routing
13  |
14  */
15  /** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */
16  const Route = use("Route");
17  const GraphQLServer = use("GraphQLServer");
18  
19  Route.post("/", context => {
20    return GraphQLServer.handle(context);
21  });
22  

Receiving unexpected "[Object: null prototype]"

Almost same like this issue apollographql/apollo-server#3149

type Mutation {
  test(payload: TestInput): TestOutput
}

input TestInput {
  id: Int!
}

type TestOutput {
  id: Int!
}

Resolver:

Mutation: {
  test: async (_, args, {auth}) => {
    return args.payload
  }
}

Query:

mutation MutationTest {
  test(payload: {id: 1}) {
    id
  }
}

Results:

[Object: null prototype] {
  id: 1
}

๐Ÿ˜•

EBADCSRFTOKEN: Invalid CSRF token

hi all of you @Xstoudi @RomainLanz i made a simple example of hellow world then wjen i access the GraphIQL route i find the result of :

{
  "error": {
    "message": "EBADCSRFTOKEN: Invalid CSRF token",
    "name": "HttpException",
    "status": 403,
    "frames": [
      {
        "file": "node_modules/@adonisjs/shield/src/Shield/index.js",
        "filePath": "/home/XXXXXXXXXXX/tests/Adonis_GraphQL/node_modules/@adonisjs/shield/src/Shield/index.js",
        "method": "Shield.verifyToken",
        "line": 268,
        "column": 13,
        "context": {
          "start": 263,
          "pre": "   *\n   * @throws {HttpException} If unable to verify secret\n   */\n  verifyToken (secret, token) {\n    if (!csrf.verify(secret, token)) {",
          "line": "      throw new GE.HttpException('Invalid CSRF token', 403, 'EBADCSRFTOKEN')",
          "post": "    }\n  }\n\n  /**\n   * Returns the csrf token by reading it from one of expected"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/@adonisjs/shield/src/Shield/index.js",
        "filePath": "/home/XXXXXXXXX/tests/Adonis_GraphQL/node_modules/@adonisjs/shield/src/Shield/index.js",
        "method": "Shield.handle",
        "line": 393,
        "column": 12,
        "context": {
          "start": 388,
          "pre": "     * If the request url and method is supposed to be checked\n     * against csrf attack, then verify the token.\n     */\n    if (this._isCsrfEnabled() && this._fallsUnderValidationUri(request) && this._fallsUnderValidationMethod(request.method())) {\n      const csrfToken = this.getCsrfToken(request)",
          "line": "      this.verifyToken(csrfSecret, csrfToken)",
          "post": "    }\n\n    /**\n     * Generate a new token for each request, if verification\n     * was skipped or passed."
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "internal/process/next_tick.js",
        "filePath": "internal/process/next_tick.js",
        "method": "process._tickCallback",
        "line": 68,
        "column": 7,
        "context": {},
        "isModule": false,
        "isNative": true,
        "isApp": false
      }
    ]
  }
}

until i disable the POST Method from the config/shield.js file

Creating own graphql directive

I would want to make own graphql directive for automatically authenticate user in resolvers etc
Something like middleware in adonis

example

directive @isAuthenticated on QUERY | FIELD
directive @hasScope (scope: [String]) on QUERY | FIELD

type Query {
  articles: String @isAuthenticated
}

For this directives I must create resolver function and put it to specific param directiveResolvers in function makeExecutableSchema
docs here

As describes in this docs makeExecutableSchema method has params

  typeDefs,
  resolvers, // optional
  logger, // optional
  allowUndefinedInResolve = false, // optional
  resolverValidationOptions = {}, // optional
  directiveResolvers = null, // optional
  schemaDirectives = null,  // optional
  parseOptions = {},  // optional
  inheritResolversFromInterfaces = false  // optio

but i's not possible in current implementation ๐Ÿ˜ข

this.$schema = makeExecutableSchema({ typeDefs, resolvers })

Thank YOU!

Wrong in naming schema file

Please fix the command to create the schema file. And if you can, please add support for graphiql.

Thanks :)

Adding middleware

Is there any way to add middleware? For instance: https://github.com/maticzav/graphql-shield

I tried

const permissions = require('./permissions')

module.exports = {
  options: {
    debug: true,
    endpointURL: '/',
    tracing: true,
    cacheControl: true
    middlewares: [permissions], // Here
  },

  middlewares: [permissions], // And here
  schema: join(__dirname, '../app/Schema'),
  resolvers: join(__dirname, '../app/Resolvers'),
}

Request more documentations

How to access the parent fields ?
GraphQl of adonnisJS look like deferent to the others GraphQL of (expressjs,koa,hapi...);
hopfully you can make a documentation in the main website , as i believe of the GraphQL and the similaires as falcor are the future of the web instead of the traditional RESTful API;
sorry about my weakness in English

Fatal error when graphql.options is undefined

I didn't have an defined graphql.config param and after update my aplication falled down

with error "Uncaught TypeError: Cannot convert undefined or null to object" in

Object.assign(this.$options, options)

I suppose

this.$options = config.get("graphql.options");

should have an default value, like

this.$options = config.get("graphql.options") || {}

Feature: GraphQL Subscriptions

I am sure you have been thinking about this too. Just want to open an issue to track this and share ideas.

I noticed there is active development in adonis-websocket repo, which means it might be released soon.

On the other hand, writing custom transport for GraphQL would be quite an undertaking. I looked at the code of subscriptions-transport-ws and there are a lot of moving parts. Maintaining a separate package just for Adonis might be a huge overhead.

Not sure if there is a way to marry the two.

Any thoughts on this? Would perhaps the standard subscriptions-transport-ws way with Redis backing would suffice for most use cases? Maybe the PubSub backend could be just configurable via a provider.

JS syntax errors in resolvers can be hard to track down

merge-graphql-schema's fileLoader uses require() to load js files. If a resolver contains a syntax error, all but the vaguest details get swallowed up (at least in my setup). No file name, no line number.

I'm filing it here in case you might be open to some kind of workaround. adonis-graphql calls fileLoader in the GraphQLServer constructor, so the upshot is that a single typo in a resolver causes a backtrace even for adonis -h:

$ adonis --help

SyntaxError: Unexpected token ,

1 anonymous
/Users/thunder/node/tk-server/node_modules/merge-graphql-schemas/dist/index.cjs.js:3778

2 fileLoader
/Users/thunder/node/tk-server/node_modules/merge-graphql-schemas/dist/index.cjs.js:3768

3 new GraphQLServer
/Users/thunder/node/tk-server/node_modules/adonis-graphql/src/Server/index.js:17

4 Object.app.singleton [as closure]
/Users/thunder/node/tk-server/node_modules/adonis-graphql/providers/GraphQLProvider.js:36

5 Ioc._resolveBinding
/Users/thunder/node/tk-server/node_modules/@adonisjs/fold/src/Ioc/index.js:231

Happy to submit a PR if you think there's anything we could do in adonis-graphql to provide better errors when resolvers fail to load (e.g.: have not tried this, but this thread seems to suggest there are some private properties we might be able to fish out and print: nodejs/node#12383 )

Authentication

Could anyone provide an example of using the adonis authentication with this?
For example, I have a login resolver, where I want to create a JWT Token and return it to the user.

 login: async (parent, args, { auth }, info) => {
      try {
        const token = await auth.attempt(args.auth)
        return { token }
      } catch (error) {
        throw new GraphQLError(error.message)
      }
    }

I can see auth is passed in the context if I log it, but it just returns "Cannot convert object to primitive value" when I try to use it like the above. Would be glad of any help.

Thanks

Security questions.

I've been developing an app with this package but recently I started reading more about graphql security and so on, I was wondering if there is a way to use https://github.com/stems/graphql-depth-limit for example, and are there any tips or advice that you can give me on this matter ?

Or code examples for directives for example, because as of now, Adonis doesn't allow using middleware in controllers like Laravel: https://laravel.com/docs/5.5/controllers#controller-middleware and the only way to validate requests and data with graphql that I tought of is done inside the controller.

Thank you in advance,
Great work on this package.

npm repo must be updated

hi @RomainLanz @targos @Xstoudi @andruu after i installed this provider i got a problem by the command

adonis make:gschema hello

it make a subfolder as the following: config/..ap/schema/Hello.graphql and if someone didnt use the ace command and create them manually it will produce an error as the following:

Error: Specified query type "Query" not found in document.

at /home/XXXXXX/Projects/tests/Adonis_GraphQL/start/routes.js(anonymous):19
  
/** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */
const Route = use('Route')

const GraphQLServer = use('GraphQLServer') // <==== this is line 19
Route.post('/', (context) => {
  return GraphQLServer.handle(context)
})  

then when i fellowed the source i got the bug made by the config/graphql.js then i tried to fork and fix its without this bug and clean
DeepinScreenshot_select-area_20190724183226

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.