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:
Hey, I want know a possibility to send an array of errors using the GraphQL module.
Is it possible with GraphQL module using a mutation? I have no idea how to implement it.
Big thanks.
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?
Since apollo-server-express
is not working in the Nest way, a new middleware, that adapts to the Exception handling of Nest should be created. The original issue was created in @nestjs/nest
since the example in the documentation leads to use this library.
Related issue nestjs/nest#556
I found an issue regarding guards. Let's take the following example:
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Observable } from 'rxjs';
import { Reflector } from '@nestjs/core';
@Injectable()
export class RolesGuard implements CanActivate {
constructor(private readonly reflector: Reflector) {}
canActivate(context: ExecutionContext): boolean {
const roles = this.reflector.get<string[]>('roles', context.getHandler());
if (!roles) {
return true;
}
const request = context.switchToHttp().getRequest();
const user = request.user;
return user && user.role && roles.some((role) => role === user.role));
}
}
Now, in the rest of the framework this works like a charm. But whenever you are in graphql, this doesn't work quite as well. Taking the following .gql
file.
type Bookings implements Node {
id: ID!
...
}
type BookingEdge {
cursor: ID!
node: Booking
}
type BookingConnection {
edges: [BookingEdge]
nodes: [Booking]
pageInfo: PageInfo!
totalCount: Int!
}
type Restaurant implements Node {
id: ID!
orders(first: Int, after: String, last: Int, before: String):OrderConnection
...
}
type Query {
restaurant(id: ID!): Restaurant
}
For the following query, the const request = context.switchToHttp().getRequest();
becomes the user.
query ($id: ID!) {
restaurant(id: $id) {
id
bookings {
nodes {
id
}
}
}
}
So, in this query, request.user
in the guard, becomes undefined
and you have to make a workaround:
canActivate(context: ExecutionContext): boolean | Promise<boolean> {
const roles = this.reflector.get<string[]>('roles', context.getHandler());
const request = context.switchToHttp().getRequest(); //this works only for when querying a parent type
const ctx = context.getArgByIndex(2); // this works for when querying a child.
const user = request.user || ctx.user;
return user && user.role && roles.some((role) => role === user.role));
}
Can you guys check if it happens to you or it's an issue of mine? Thank you.
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
I have a question; I have the following scheme:
scalar qq
type Liquid {
nliquid: Int
fecha: qq
}
type Query {
liquidaciones: [Liquid]
}
why when sending the query
{
liquidaciones{
nliquid
fecha
}
}
get the next result
{
"data": {
"liquidaciones": [
{
"nliquid": 1,
"fecha": "2004-11-16T03:00:00.000Z",
},
{
"nliquid": 2,
"fecha": "2004-12-13T03:00:00.000Z",
"descrip": "NOVIEMBRE 2004"
}
}
without having defined the scalar qq, even changing qq for any other text (other than Int, String, Float or ID)
how to test graphql use nestjs
I'm submitting a...
Current behavior
When I try to inject GraphQLFactory
into either a factory function or a class passed to GraphQLModule.forRootAsync()
, the app fails to bootstrap, with no error displayed in the console.
Expected behavior
I think I should be able to inject GraphQLFactory
and use it in a factory or class passed to .forRootAsync()
.
Minimal reproduction of the problem with instructions
git clone [email protected]:nestjs/nest.git
cd nest/sample/12-graphql-apollo
npm install
- edit app.module.ts to look like:
imports: [
CatsModule,
GraphQLModule.forRootAsync({
useFactory(graphQLFactory: GraphQLFactory) {
return {
typePaths: ['./**/*.graphql'],
installSubscriptionHandlers: true,
};
},
inject: [GraphQLFactory]
}),
],
npm run start
What is the motivation / use case for changing the behavior?
I want to use the GraphQLFactory.mergeTypesByPaths()
method to do some pre-processing of my schema when bootstrapping my app. Up until today I was using the old v3.0.0 way of configuring graphql, where I could inject GraphQLFactory
into my AppModule.
Now I am upgrading to v5.1.0 and it seems that when I try to inject GraphQLFactory
into either a factory function or a class passed to GraphQLModule.forRootAsync()
, the app fails to bootstrap with no error.
Environment
Nest version: 5.3.0
"@nestjs/common": "^5.3.0",
"@nestjs/core": "^5.3.0",
"@nestjs/graphql": "^5.1.0",
Hi!
I just discovered this framework and I have to say it’s awesome. Kudos!
The GraphQL module is great, but I did not find any information regarding how to do batching and caching, which is pretty required to avoid a big waste of resources (see https://github.com/facebook/dataloader).
Given the fact that resolvers are automatically mapped, I guess there’s currently no way to do that, right? An integration with dataloader would be awesome, if not mandatory for any medium to large application.
And, happy new year, by the way. ☺️
My AppModule have this configuration https://docs.nestjs.com/graphql/quick-start, but a need to upload a file with multipart/form-data, i added a new Module with a Controller with this method:
@Post('upload') @UseInterceptors(FileInterceptor('file', { storage })) async uploadFile(@UploadedFile() file, @Response() res) { return {}; }
this method never respond to a client
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.
-