Git Product home page Git Product logo

adonis-gql's People

Contributors

angelomsq avatar higoribeiro 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

Watchers

 avatar  avatar  avatar  avatar

adonis-gql's Issues

Invalid CSRF token

Hello i start a helloWorld example then i got this issue

{
  "error": {
    "message": "EBADCSRFTOKEN: Invalid CSRF token",
    "name": "HttpException",
    "status": 403,
    "frames": [
      {
        "file": "node_modules/@adonisjs/shield/src/Shield/index.js",
        "filePath": "
~/tests/AdoGraph/node_modules/@adonisjs/shield/src/Shield/index.js",
        "method": "Shield.verifyToken",
        "line": 268,
        "column": 13,
        "context": {
          "start": 263,
...

when i change config/shield.js at crsf.methods to be without POST its work

//config/shield.js
'use strict'

module.exports = {
  ...
  /*
  |--------------------------------------------------------------------------
  | CSRF Protection
  |--------------------------------------------------------------------------
  |
  | CSRF Protection adds another layer of security by making sure, actionable
  | routes does have a valid token to execute an action.
  |
  */
  csrf: {
    enable: true,
    methods: ['PUT', 'DELETE'],
    filterUris: [],
    cookieOptions: {
      httpOnly: false,
      sameSite: true,
      path: '/',
      maxAge: 7200
    }
  }
}

its work and return

{
  "data": {
    "hello": "World"
  }
}

Upload scalar doesn't work

does any of the community success to use the Upload scalar ?
i made this example without success

// app/Controllers/Gql/Mutations/FileController.js
'use strict'

class FileController {
  async singleUpload(root, args, {request}) {

    console.log("it Should log this msg <Hello from the resolver>"); //<--- But doesn't log it !! , it seem there's an issue with Upload Scalar resolver

    const file = request.file("file", {
      types: ["image"],
      size: "5mb"
    });

    if (file == null) {
      console.log(err);
      return "err";
    }

    return {
      path: "path",
      filename: "filename",
      mimetype: "mimetype",
      encoding: "encoding"
    }
  }
}

module.exports = FileController
// start/graphql.js
'use strict'

const Gql = use('Gql')

Gql.schema('File', () => {
  Gql.mutation('Mutations/FileController')
})
# app/Schemas/File.graphql
scalar Upload

type File {
  path: String
  filename: String
  mimetype: String
  encoding: String
}

type Mutation {
  singleUpload(file: Upload, txt: String): File
}

when i upload an image file it return error on client side there's no error on the server side

{
  "error": {
    "message": "Must provide document",
    "name": "Error",
    "status": 500,
    "frames": [
      {
        "file": "node_modules/graphql/jsutils/devAssert.js",
        "filePath": "~/test_adonis-gql/node_modules/graphql/jsutils/devAssert.js",
        "method": "devAssert",
        "line": 12,
        "column": 11,
        "context": {
          "start": 7,
          "pre": "\nfunction devAssert(condition, message) {\n  var booleanCondition = Boolean(condition);\n\n  if (!booleanCondition) {",
          "line": "    throw new Error(message);",
          "post": "  }\n}\n"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/graphql/validation/validate.js",
        "filePath": "~/test_adonis-gql/node_modules/graphql/validation/validate.js",
        "method": "Object.validate",
        "line": 52,
        "column": 41,
        "context": {
          "start": 47,
          "pre": "\nfunction validate(schema, documentAST) {\n  var rules = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _specifiedRules.specifiedRules;\n  var typeInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new _TypeInfo.TypeInfo(schema);\n  var options = arguments.length > 4 ? arguments[4] : undefined;",
          "line": "  documentAST || (0, _devAssert.default)(0, 'Must provide document'); // If the schema used for validation is invalid, throw an error.",
          "post": "\n  (0, _validate.assertValidSchema)(schema);\n  var abortObj = Object.freeze({});\n  var errors = [];\n  var maxErrors = options && options.maxErrors;"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/apollo-server-core/dist/runQuery.js",
        "filePath": "~/test_adonis-gql/node_modules/apollo-server-core/dist/runQuery.js",
        "method": "doRunQuery",
        "line": 111,
        "column": 42,
        "context": {
          "start": 106,
          "pre": "        var rules = graphql_1.specifiedRules;\n        if (options.validationRules) {\n            rules = rules.concat(options.validationRules);\n        }\n        logFunction({ action: LogAction.validation, step: LogStep.start });",
          "line": "        var validationErrors = graphql_1.validate(options.schema, documentAST, rules);",
          "post": "        logFunction({ action: LogAction.validation, step: LogStep.end });\n        if (validationErrors.length) {\n            return Promise.resolve({\n                errors: format(validationErrors, options.formatError),\n            });"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/apollo-server-core/dist/runQuery.js",
        "filePath": "~/test_adonis-gql/node_modules/apollo-server-core/dist/runQuery.js",
        "method": null,
        "line": 21,
        "column": 56,
        "context": {
          "start": 16,
          "pre": "    LogStep[LogStep[\"start\"] = 0] = \"start\";\n    LogStep[LogStep[\"end\"] = 1] = \"end\";\n    LogStep[LogStep[\"status\"] = 2] = \"status\";\n})(LogStep = exports.LogStep || (exports.LogStep = {}));\nfunction runQuery(options) {",
          "line": "    return Promise.resolve().then(function () { return doRunQuery(options); });",
          "post": "}\nexports.runQuery = runQuery;\nfunction printStackTrace(error) {\n    console.error(error.stack);\n}"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      }
    ]
  }
}

Pagination

Can you make a tutorial how to integrate PageInfo using Connections?

This an example with adonis-grapple
image

Thank you

how to Assign a resolver function to a field.

hi @HigoRibeiro @angelomsq ; i'm trying to assign a resolver function to a field as lighthouse on Laravel did:

type Query {
  jobs: [Job!]! @field(resolver: "App\\Http\\GraphQL\\Query@jobs")
}

how can i do it ?
(im not sure about the right question ,whenever im trying to get a relation between the authors and them books

# Schema.grahpql
type Query {
  book(id:ID!): [Book]
  author(id:ID!): [Author]

  books: [Book]
  authors: [Author]
}

type Book{
  id:ID
  title:String
  author:[Author]
  address:String
}
type Author{
  id:ID
  name:String
  age:Int
  books:[Book]
} 
// SchemaController.js
var books=[
  {id:1,auth_id:1,title:'Lead Group Developer'},
  {id:2,auth_id:1,title:'Legacy Optimization Administrator'},
  {id:3,auth_id:2,title:'Human Directives Engineer'},
  {id:4,auth_id:4,title:'Global Intranet Director'},
  {id:5,auth_id:3,title:'Internal Operations Analyst'},
  {id:6,auth_id:5,title:'Internal Factors Architect'},
  {id:7,auth_id:5,title:'Customer Program Agent'},
  {id:8,auth_id:4,title:'Direct Program Associate'},
  {id:9,auth_id:3,title:'Future Directives Planner'},
  {id:10,auth_id:6,title:'Customer Functionality Engineer'},
  {id:11,auth_id:1,title:'Global Creative Producer'},
]
var authors=[
  {id:1,name:'Stella Moreno',age:23,address:'232 Itipa River'},
  {id:2,name:'Christina Parks',age:86,address:'1719 Nijan Turnpike'},
  {id:3,name:'Antonio Edwards',age:50,address:'1768 Bekep Glen'},
  {id:4,name:'Rosa Bailey',age:30,address:'167 Cagwe Park'},
  {id:5,name:'Ollie Lewis',age:88,address:'1205 Nidoh Boulevard'},
  {id:6,name:'Sam Ford',age:64,address:'900 Akhih Terrace'},
]
class SchemaController {
  async books() {
    return books
  }
  async authors() {
    return authors
  }
  async book(parent, arg) {
    return books.filter(b=>b.id==arg.id)
  }
  async author(parent, arg) {
    return authors.filter(a=>a.id==arg.id)
  }
/**
  * im trying to make the BookType to resolve this function when i query for the book author
  * coz it's return null
  * @example
  * ```query
  * {
  *   book(id:1){
  *      title # work
  *      author{  # return null coz cant attach the Book author field to a resolver which
  *               # filter the authors by the parent `id` @ `auth_id` on the authors array
  *         name
  *         id
  *       }
  *   }
  *```
  */
  // async authorBook(parent, arg, ctx) {
  //   return books.filter(a=>a.id==parent.auth_id)
  // }
}
 
module.exports = SchemaController

Scope of works

Provider basic

  • Provider base
  • Read schema
  • Read Resolver
  • Tests
  • Commands

Provider Advanced

  • Directive support
  • Accept middleware
  • Subscription System

Nested resolvers

Any example to work with nested resolver in queries?
Thank you

[Question] How to set resolveType method on request return

Hello
I have this graphql structure

## Mutation
#

type Organization {
  uuid: ID
  name: String
  initials: String
}

type OrganizationResultSuccess {
  organization: Organization!
}

type OrganizationInvalidInputError {
  message: String!
  field: String!
  validation: String!
}

input OrganizationInput {
  name: String!
  initials: String!
}

union OrganizationResult = OrganizationResultSuccess | OrganizationInvalidInputError

type Mutation {
  addOrganization(organization: OrganizationInput!): OrganizationResult
}

I set up the following test for the playground

mutation {
  addOrganization (organization:{
    name:"Inex Ltda.",
    initials:"Inex"
  }) {
    ... on OrganizationResultSuccess {
      organization {
        uuid
        name
        initials
      }
    }
    ... on OrganizationInvalidInputError {
      message
      field
      validation
    }
  }
}

returns me the following error

{
  "data": {
    "addOrganization": null
  },
  "errors": [
    {
      "message": "Abstract type OrganizationResult must resolve to an Object type at runtime for field Mutation.addOrganization with value { resolveType: [function resolveType], __resolveType: [function __resolveType], organization: { name: \"Inex Ltda.\", initials: \"Inex\" } }, received \"undefined\". Either the OrganizationResult type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addOrganization"
      ]
    }
  ]
}

I am unable to configure the return methods being requested.

'use strict'

class OrganizationController {
  async addOrganization (parent, arg, ctx) {
    const { organization } = arg

    return {
      // resolveType: () => 'OrganizationResult', // <- both not work
      // __resolveType: () => 'OrganizationResult', // <-
      organization
    }
  }

}

module.exports = OrganizationController

@HigoRibeiro how can I solve this?

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.