I'm submitting a...Bug report
[ ] Regression
[*] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Hello,
I'm using the graphql example( in the example directory of nest) with the Cat CRUD and i try to use a union type and interface but i didn't find a way to do it.
When i try to request my data with a fragment, i have the following error :
"Abstract type MutationResult must resolve to an Object type at runtime for field Mutation.createCat with value "[object Object]", received "undefined". Either the MutationResult type should provide a "resolveType" function or each possible types should provide an "isTypeOf" function."
There is nothing in the doc explaining how to use union / interface, and there is nothing in the graphql example.
In the apollo documentation, the type resolver ( here "Cat" Resolver") should implement a __resolveType function. I tried to set this function in the @resolver('Cat') class CatsResolvers
but it's not working.
I tried to add it on the cat resolvers class
Expected behavior
The request should return either a Cat item or GraphQLErrorItem from my schema definition.
Minimal reproduction of the problem with instructions
export interface GraphQLError {
readonly message: string;
readonly errorCode: number;
readonly type: string;
}
type GraphQLError {
message: String
errorCode: Int
type: String
}
union MutationResult = Cat | GraphQLError
- change the createCat Mutation in the schema
- createCat(name: String, age: Int): MutationResult
- add the function in cats.resolvers.ts in the CatsResolvers class
__resolveType(obj, context, info): string{
return obj.errorCode ? 'GraphQLError' : 'Cat';
}
What is the motivation / use case for changing the behavior?
Environment
Nest version: 4.5.10 (core)
For Tooling issues:
- Node version: 9.4
- Platform: Mac
Others:
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Using Nestjs with the GraphQLModule as documentation describes, there are a problem with throwing HttpException. The error message that GraphQL returns, contains "[Object Object"] in the message field instead the HttpException message.
The GraphQL.js library is expecting an Error instance, but HttpException not inherit from Error. What is the main reason for HttpException is not extending from Error?
In addition to this any Exception Filter is not working.
Expected behavior
Proper error handling and Exception Filters working with GraphQL.
Minimal reproduction of the problem with instructions
Install @nestjs/graphql and configure it as documentation describes. In any resolver try to throw a HttpException (or a inherited custom one). GraphQL returns an error like this:
{
"data": {
"findOneUserById": null
},
"errors": [
{
"message": "[object Object]",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"findOneUserById"
]
}
]
}
What is the motivation / use case for changing the behavior?
Proper error handling working with GraphQL and documentation for how to deal with this.
Environment
- "@nestjs/common": "^4.5.9",
- "@nestjs/core": "^4.5.10",
- "@nestjs/graphql": "^2.0.0",
- "@nestjs/microservices": "^4.5.8",
- "@nestjs/testing": "^4.5.5",
- "@nestjs/websockets": "^4.5.8",
For Tooling issues:
- Node version: 9.4.0
- Platform: Linux
Others:
- Kubuntu
- WebStorm
- GraphiQL
- npm
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
{
"error": "Could not connect to websocket endpoint ws://localhost:3000/graphql. Please check if the endpoint url is correct."
}
Expected behavior
It should subscribe to changes.
Minimal reproduction of the problem with instructions
Checkout https://github.com/nestjs/nest/tree/master/sample/12-graphql-apollo
Fire subscription query
subscription {catCreated {id name}}
What is the motivation / use case for changing the behavior?
Well its a bug - so ^^
Environment
Nest version: latest
For Tooling issues:
- Node version: 9
- Platform Mac
Hi guys,
I started to use the GraphQL module and I must say that it is awesome. However, I had some difficulties to perform POST requests against my GraphQL endpoints (GET requests works out of the box).
I'm using the following packages:
"dependencies": {
"@nestjs/common": "^4.5.4",
"@nestjs/core": "^4.5.4",
"@nestjs/graphql": "^2.0.0",
"@nestjs/microservices": "^4.5.3",
"@nestjs/testing": "^4.5.4",
"@nestjs/websockets": "^4.5.3",
...
"apollo-server-express": "^1.3.2",
"graphql": "^0.11.7",
"graphql-tools": "^2.11.0",
...
}
Here is my GraphQL module implementation, according to the Nestjs documentation:
import {Module, NestModule, MiddlewaresConsumer, RequestMethod} from '@nestjs/common';
import {graphqlExpress, graphiqlExpress} from 'apollo-server-express';
import {GraphQLFactory, GraphQLModule} from '@nestjs/graphql';
import {SnippetResolvers} from "./snippet/snippet.resolvers";
import {SnippetModule} from "../snippet/snippet.module";
@Module({
imports: [
GraphQLModule,
SnippetModule
],
components: [
SnippetResolvers
]
})
export class GQLModule implements NestModule {
constructor(private readonly graphQLFactory: GraphQLFactory) {}
configure(consumer: MiddlewaresConsumer) {
const typeDefs = this.graphQLFactory.mergeTypesByPaths('./**/*.graphql');
const schema = this.graphQLFactory.createSchema({ typeDefs });
consumer
.apply(graphiqlExpress({ endpointURL: '/graphql' }))
.forRoutes({ path: '/graphiql', method: RequestMethod.GET })
.apply(graphqlExpress(req => ({ schema, rootValue: req })))
.forRoutes({ path: '/graphql', method: RequestMethod.ALL });
}
}
With the following request:
POST /graphql HTTP/1.1
Host: localhost:3000
Content-Type: application/graphql
Cache-Control: no-cache
{ snippets {name}}
I get the following response:
HTTP 500
POST body missing. Did you forget use body-parser middleware?
I found the solution reading some Apollo documentation; all I had to do was to add the following middlewares to my endpoint:
import {Module, NestModule, MiddlewaresConsumer, RequestMethod} from '@nestjs/common';
import {graphqlExpress, graphiqlExpress} from 'apollo-server-express';
import {GraphQLFactory, GraphQLModule} from '@nestjs/graphql';
import {SnippetResolvers} from "./snippet/snippet.resolvers";
import {SnippetModule} from "../snippet/snippet.module";
import * as bodyParser from 'body-parser';
@Module({
imports: [
GraphQLModule,
SnippetModule
],
components: [
SnippetResolvers
]
})
export class GQLModule implements NestModule {
constructor(private readonly graphQLFactory: GraphQLFactory) {}
configure(consumer: MiddlewaresConsumer) {
const typeDefs = this.graphQLFactory.mergeTypesByPaths('./**/*.graphql');
const schema = this.graphQLFactory.createSchema({ typeDefs });
consumer
.apply(bodyParser.text({ type: 'application/graphql' }))
.forRoutes({ path: '/graphql', method: RequestMethod.ALL })
.apply((req, res, next) => {
if (req.is('application/graphql')) {
req.body = { query: req.body };
}
next();
})
.forRoutes({ path: '/graphql', method: RequestMethod.ALL })
.apply(graphiqlExpress({ endpointURL: '/graphql' }))
.forRoutes({ path: '/graphiql', method: RequestMethod.GET })
.apply(graphqlExpress(req => ({ schema, rootValue: req })))
.forRoutes({ path: '/graphql', method: RequestMethod.ALL });
}
}
At this point, everything looks like working fine for me and I'm pretty happy with this solution. Could any of you give me some impression on this implementation? Is it the way to go? (if yes, then we should maybe add those details to the documentation)
Thanks for your time 😄
I'm submitting a...
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I cant't figure out how set custom header during a query request.
Header decorator, doesn't work, nor Response decorator.
Let me know if there is another way.
Expected behavior
There should be the ability to use header decorator as for the controller:
@Header('x-custom-header', 'xxxx')
@query('books')
async getBooks() {
....
}
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
If the parent resolver and the child resolver both have Guard, the validate function of the guard will be triggered twice. The guard of parent will be passed with the request object, while the guard of the child will be passed with whatever parent resolver returns.
@Resolver('User')
export class UserResolvers {
constructor(
private readonly userService: UserService
) {}
@UseGuards(CustomGuard) // validate function here will get request object
@Query('me')
async getUser(obj, args, context, info) {
const { user } = context
return {
account_type: user.accountType,
balance: user.balance,
currency: user.currency,
id: user.accountId
}
}
@UseGuards(CustomGuard) // validate function here will get the result of getUser
@ResolveProperty('balance')
async getBalance(obj, args, context, info) {
if (obj.balance) return obj.balance
const data = await this.userService.getAccount(context, context.user.session)
return data.balance
}
}
When I using the sample/12-graphql-apollo project, and I remove the graphql file, then run this project.
It throws some error:
(node:5278) UnhandledPromiseRejectionWarning: Error: Specified query type "Query" not found in document.
at /home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/graphql/utilities/buildASTSchema.js:133:17
at Array.forEach (<anonymous>)
at Object.buildASTSchema (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/graphql/utilities/buildASTSchema.js:126:30)
at buildSchemaFromTypeDefinitions (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/graphql-tools/src/schemaGenerator.ts:225:32)
at _generateSchema (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/graphql-tools/src/schemaGenerator.ts:92:18)
at Object.makeExecutableSchema (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/graphql-tools/src/schemaGenerator.ts:120:20)
at GraphQLFactory.createSchema (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/@nestjs/graphql/dist/graphql.factory.js:23:32)
at ApplicationModule.createSchema (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/src/app.module.ts:41:32)
at ApplicationModule.configure (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/src/app.module.ts:24:25)
at MiddlewareModule.loadConfiguration (/home/dzzzzzy/workspace/nestjs/nest/sample/12-graphql-apollo/node_modules/@nestjs/core/middleware/middleware-module.js:35:18)
(node:5278) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:5278) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
When console.log(typeDefs)
with none graphql file at other projects, it always throw this error and console shows:
It is possible to provide RXJS support for resolver functions (@Query()
, @Mutation()
, @ResolveProperty()
, ...) ? Like nest route handler, they could return RXJS observable streams :
@Query()
findAll(): Observable<any[]> {
return of([]);
}
I using fastify in nestjs as default, but i can not using this package. How should I do it?
Here is a good example on how to apply Auth in GraphQL using Directive Resolvers as "resolvers middlewares" -> https://blog.graph.cool/graphql-directive-permissions-authorization-made-easy-54c076b5368e. Currently this module don't support to define directives, even that graphql-tools
allows it.
I don't know how that is handled in combination with Guards/Interceptors of Nest. Using this kind of directives allow the Schema definition to be discovered by the users and depending the role to show or hide specific fields.
I have the following code snippet that works fine in graphql-yoga.
Subscription: {
post: {
subscribe: (parent, args, ctx, info) => {
return ctx.db.subscription.post(
{
where: {
mutation_in: ["CREATED", "UPDATED"]
}
},
info
);
}
}
},
If I try to get the context in the Nest way - all of those args are undefined
@Subscription('post')
onPostMutation(parent, args, ctx, info) {
// all args are undefined
// ...
}
So my question - how to get context and args for a subscription?
Hi,
I have an issue, when merge types and create schema, on terminal console show errors like this:
node:8726) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: buildASTSchema.getDescription is not a function
(node:8726) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled willterminate the Node.js process with a non-zero exit code.
this is my code
const typeDefs = this.graphQLFactory.mergeTypesByPaths('./**/*.graphql');
const schema = this.graphQLFactory.createSchema({ typeDefs });
consumer
.apply(graphqlExpress(req => ({ schema: {}, rootValue: req })))
.forRoutes({ path: '/graphql', method: RequestMethod.ALL });
Ho can the query method be passed to the right Query type parent?
Or how can the resolver class be annotated correctly in order to resolve?
.graphql
type CustomQuery{
foo: String
}
type Query {
mw: CustomQuery
}
CustomResolver
import { Query, Resolver } from '@nestjs/graphql';
@Resolver()
export class CustomResolver {
constructor() {}
@Query()
foo(): string {
return 'bar';
}
}
create schema
const typeDefs = this.graphQLFactory.mergeTypesByPaths( './**/*.graphql');
const schema = this.graphQLFactory.createSchema({ typeDefs });
result
{
"data": {
"mw": {
"foo": null
}
},
"extensions": {
"tracing": {
"version": 1,
"startTime": "2018-02-20T17:01:09.202Z",
"endTime": "2018-02-20T17:01:09.202Z",
"duration": 242964,
"execution": {
"resolvers": [
{
"path": [
"mw"
],
"parentType": "Query",
"fieldName": "mw",
"returnType": "CustomQuery",
"startOffset": 77828,
"duration": 96395
},
{
"path": [
"mw",
"foo"
],
"parentType": "CustomQuery",
"fieldName": "foo",
"returnType": "String",
"startOffset": 214124,
"duration": 8691
}
]
}
}
}
}
maybe relevant dependencies
{
"dependencies": {
"@nestjs/common": "4.6.4",
"@nestjs/core": "4.6.4",
"@nestjs/graphql": "2.0.0",
"@types/graphql": "0.12.4",
"graphql": "0.13.1",
"graphql-tools": "2.21.0"
}
}
A) What am I doing wrong?
B) Can anyone confirm that custom query types are not supported at the moment?
C) Would a PR supporting this via annotation be welcomed?
Recommend Projects
-
-
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. 📊📈🎉
-
Recommend Topics
-
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.
-
Recommend Org
-
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.
-