romainlanz / adonis-graphql Goto Github PK
View Code? Open in Web Editor NEWGraphQL Provider for AdonisJs Framework
License: MIT License
GraphQL Provider for AdonisJs Framework
License: MIT License
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
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
}
๐
@RomainLanz, @anaalicefig, @annymosse
For some reason, I still manage to get that error. I have included a screenshot.
Originally posted by @fsavalam in #27 (comment)
hello , i got this repo https://github.com/jaydenseric/graphql-upload which provide an ability to create a custom Upload scalar with a custom middleware like Express & Koa .
However i couldn't make it success with this provider , is there some one of the community success to create work ?
@RomainLanz what do you suggest ?
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
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 ๐ข
adonis-graphql/src/Server/index.js
Line 19 in 0604f5e
Thank YOU!
how to access the parent in resolvers?
Please fix the command to create the schema file. And if you can, please add support for graphiql.
Thanks :)
How can I enable autorefresh server when changed *.graphql file?
Now after change schema User.graphql nothing happens, I have to restart server or edit any js file
Thank you!
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'),
}
When run adonis make:gschema Product it creates app/Schema/Product.js instead app/Schema/Product.graphql
adonis-graphql/commands/MakeSchema.js
Line 45 in 971d196
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
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
adonis-graphql/src/Server/index.js
Line 34 in 678bd93
I suppose
this.$options = config.get("graphql.options");
should have an default value, like
this.$options = config.get("graphql.options") || {}
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.
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:37782 fileLoader
/Users/thunder/node/tk-server/node_modules/merge-graphql-schemas/dist/index.cjs.js:37683 new GraphQLServer
/Users/thunder/node/tk-server/node_modules/adonis-graphql/src/Server/index.js:174 Object.app.singleton [as closure]
/Users/thunder/node/tk-server/node_modules/adonis-graphql/providers/GraphQLProvider.js:365 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 )
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
I try do upload but don`t work
type File {
filename: String!
mimetype: String!
encoding: String!
}
type Query {
uploads: [File]
}
type Mutation {
singleUpload(file: Upload!): File!
}
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.