Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Apr 08 22:05
  • Apr 06 17:31
  • Apr 06 13:42
    Carassale commented #803
  • Apr 06 07:25
    MichalLytek commented #545
  • Apr 06 07:24
    MichalLytek commented #545
  • Apr 06 07:24
    MichalLytek commented #545
  • Apr 06 05:13
  • Apr 06 03:39
    adventurini commented #664
  • Apr 04 19:24
    MichalLytek deleted #847
  • Apr 04 19:23
    MichalLytek locked #847
  • Apr 04 19:23
    MichalLytek closed #847
  • Apr 04 17:58
    vytautas-pranskunas- edited #847
  • Apr 04 17:58
    vytautas-pranskunas- edited #847
  • Apr 04 17:57
    vytautas-pranskunas- opened #847
  • Apr 02 20:31
    MichalLytek deleted #844
  • Apr 02 20:30
    MichalLytek locked #844
  • Apr 02 20:30
    MichalLytek closed #844
  • Apr 02 19:09
    xinghul opened #844
  • Apr 01 01:00
    returnzer0 commented #545
Lucas Canavesio
@luxer066
Hello! I am trying to do federation graphql and I need TypeGraphQLModule to support GraphQLFederationModule. Any suggestions?
Oliver Salzburg
@oliversalzburg
Following the suggestion to split up my resolvers into multiple files, I wanted to create a central index of all resolvers, that I can easily reference when I build my schema. However, I'm running into a typing issue I don't quite understand. I hope this code explains it:
// resolvers.ts
import {ResovlerA, ResolverB} from "somewhere";

const AllResolvers = [
    ResolverA, ResolverB
];

export {AllResolvers}

// main.ts
import {AllResolvers} from "resolvers";

await buildSchema({
  resolvers: AllResolvers,
//^^^^^^^^^
//(typeof ResolverA | typeof ResolverB) is not assignable to type [Function, ...Function[]] | ...
});
9 replies
HassanDevigital
@HassanDevigital
i am facing this error Error: connect ECONNREFUSED 127.0.0.1:54322
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
1 reply
Lucas Canavesio
@luxer066

Hello! I am trying to do federation graphql and I need TypeGraphQLModule to support GraphQLFederationModule. Any suggestions?

Hi @MichalLytek with my team we cloned typegraphql-nestjs and added support for GraphQLFederationModule combined with your example of buildFederatedSchema type-graphql and it works correctly.

We think that support could be added directly in typegraphql-nestjs. What you think?

2 replies
HassanDevigital
@HassanDevigital
i want to add file upload functionalityin my typegrtaphql project
here is anyone can help me
HassanDevigital
@HassanDevigital
please any man here to help me i am new on typegraphql
1 reply
Aman
@amandsingh

Hey all, I am new to type-graphql as well. I am facing an issue serializing a virtual field to graphl response.. I am using type-graphql with typegoose.

See the virtual property 'book' on the @ObjectType() class.

'
@ObjectType()
@modelOptions({ schemaOptions: { toJSON: { virtuals: true }, toObject: { virtuals: true } } })
export class BookRecommendation {
@Field()
readonly _id!: ObjectId;

@prop() @Field(() => Date)
createdAt!: Date;

@prop() @Field(() => Date)
updatedAt!: Date;

@prop() @Field()
sourceUrl!: string;

@prop() @Field()
recommendation!: string;

@prop({ref: Book, }) @Field(type => ObjectIdScalar)
bookId!: Ref<Book>;

@prop({ref: Influencer}) @Field(type => ObjectIdScalar)
influencerId!: Ref<Influencer>;

@prop({
ref: 'Book',
foreignField: '_id', // compare this value to the local document populate is called on
localField: 'bookId', // compare this to the foreign document's value defined in "foreignField",
justOne: true,
})
public book: Book;
}
'

I am using below code to populate the value of the book which works from typegoose, but i don't see this serialized in graphql response.
'MongooseBookReco.find().populate('book').exec(); '

Couldn't find any specific documentation in type-graphql for handing this.

Lars Krieger
@Nopzen

Quick question regarding node and resolving the resolvers field in the buildSchema since my resolvers are defined like so:

schema = await buildSchema({
      resolvers: [__dirname + "/resolvers/*.ts"],
      authChecker: queryAuthchecker,
      dateScalarMode: "isoDate",
    });

Once i compile the code the server fails starting up because there are no .ts files in resolvers/ they are all compiled to .js

I tried to do some fancy regex like you are able to in webpack, and not to my surprise this errored of course:

schema = await buildSchema({
      resolvers: [__dirname + "/resolvers/*.{ts|js}"],
      authChecker: queryAuthchecker,
      dateScalarMode: "isoDate",
    });

How should i then define my resolvers extensions? Should I make it a env var (seems clumsy) or is there something I'm missing? Also I'm not super familiar with all the facets of node :) so sorry if this is a super rookie question?

2 replies
rima13panchal
@rima13panchal
Hello. I am new in typegraphql. I am trying to upload image using typegraphql but I got error like range error - maximum call stack size exceeded. Can some share upload functionality
I am using Apollo-server-express and graphic-upload
Pablo Mentaberry
@pablojmp
hi @MichalLytek i see you solved MichalLytek/type-graphql#737, but the same issue occurs when defining an InputType with a nested array Field like this
1 reply
@InputType()
export class SearchInput {
@Field((type) => [[option]])
optionsList: option[][]
}
the option object instances are not correctly deserialized on the resolver. is this supported?
1 reply
Pablo Mentaberry
@pablojmp
i'm using the latest version (1.1.1), and yes, it works when using the nested array with the @Arg decorator, but if i add a class and decorate it with @InputType and then use @Arg('input', (type) => SearchInput) input: SearchInput (using the class above), then it doesn't work
Pablo Mentaberry
@pablojmp

added the following to the test file in functional/resolvers:

      class SampleInputNestedProperty {
        @Field(type => [[Int]])
        nested: number[][];
      }
      classes.SampleInputNestedProperty = SampleInputNestedProperty;

....

        @Mutation()
        mutationWithDoubleArrayInsideInputProperty(
          @Arg("inputs", type => SampleInputNestedProperty) inputs: SampleInputNestedProperty,
        ): number {
          mutationInputValue = inputs;
          return inputs.nested[0][0];
        }

....

it("should create instance of nested arrays from input property", async () => {
      const mutation = `mutation {
        mutationWithDoubleArrayInsideInputProperty(inputs: {nested: [[2]]})
      }`;

      const mutationResult = await graphql(schema, mutation);
      const result = mutationResult.data!.mutationWithDoubleArrayInsideInputProperty;
      const nestedInput = mutationInputValue[0][0];

      expect(mutationResult.errors).toBeUndefined();
      expect(result).toEqual(2);
      expect(mutationInputValue).toBeInstanceOf(Array);
      expect(mutationInputValue).toHaveLength(1);
      expect(mutationInputValue[0]).toBeInstanceOf(Array);
      expect(mutationInputValue[0]).toHaveLength(1);
      expect(nestedInput).toBeInstanceOf(classes.SampleInputNestedProperty);
    });
Result:
    TypeError: Cannot read property '0' of undefined

      1809 |       const mutationResult = await graphql(schema, mutation);
      1810 |       const result = mutationResult.data!.mutationWithDoubleArrayInsideInputProperty;
    > 1811 |       const nestedInput = mutationInputValue[0][0];
           |                                                ^
      1812 | 
      1813 |       expect(mutationResult.errors).toBeUndefined();
      1814 |       expect(result).toEqual(2);

      at Object.<anonymous> (tests/functional/resolvers.ts:1811:48)
Pablo Mentaberry
@pablojmp
idk if modifying something in function convertToInput(tree: TransformationTree, data: any) will help, don't know how to debug the tests
Pablo Mentaberry
@pablojmp
my bad, just fixed the tests to do this:
    it("should create instance of nested arrays from input property", async () => {
      const mutation = `mutation {
        mutationWithDoubleArrayInsideInputProperty(inputs: {nested: [[2]]})
      }`;

      const mutationResult = await graphql(schema, mutation);
      const result = mutationResult.data!.mutationWithDoubleArrayInsideInputProperty;
      const nestedInput = mutationInputValue.nested[0][0];

      expect(mutationResult.errors).toBeUndefined();
      expect(result).toEqual(2);
      expect(nestedInput).toEqual(2);
      expect(mutationInputValue.nested).toBeInstanceOf(Array);
      expect(mutationInputValue.nested).toHaveLength(1);
      expect(mutationInputValue.nested[0]).toBeInstanceOf(Array);
      expect(mutationInputValue.nested[0]).toHaveLength(1);
    });
and it works, so idk why it's failing on my case...
Pablo Mentaberry
@pablojmp
on my failling code i use [[options]] where options is decorated with InputType and contains a couple of string Field decorated properties
Fabrizio Ruggeri
@ramiel
Hello everybody. I'm Fabrizio, i'm new here. I'd want to thank you for the project, it's great, really.

I have a little curiosity and I thought to ask you. I was looking at the example code about scoped containers (https://github.com/MichalLytek/type-graphql/blob/v1.1.1/examples/using-scoped-container/index.ts) and I noticed this comment in the code

// for developers curiosity purpose, here is the logging of current scoped container instances
// we can make multiple parallel requests to see in console how this works
const instancesIds = ((Container as any).instances as ContainerInstance[]).map(
      instance => instance.id,
);
console.log("instances left in memory:", instancesIds);

I'm wondering what that means. Is this indicating a memory leak in the application? Why not all the scoped containers get removed? Why, when parallel request happen, only the last container is reset and not all of them?

5 replies
Nicolò
@hitech95

Hi guys I have a question about context and the @Authorize() decorator.
I have my login mutation that create a jwt refresh token for the frontend. but the login mutation is also return the user info of the just logged in user.

The user have some fields that are protected from the @Authurize so when returning the data an error is thrown.
@MichalLytek Suggested to ask here about it after reading something more about the grapgh-ql context.

For what I can see Typescript and Javascript pass objs and arrays by reference so I should be able to directly edit the context and add the user in it, right?

@Mutation(() => AuthResponse)
  async login(@Ctx() context: Context): Promise<AuthResponse> {
    const user = this.authService.fetchMyUser();
    context.user = user;

    return user;
  }
4 replies
Felipe Rocha
@felipellrocha
Hey. I'm trying to create a generic Result type, so that I can do error handling locally, instead of using a global errors array. But I cannot create the generic over either Enum or Union. Has anyone been able to accomplish that work before so I can see an example?
2 replies
vanthao03596
@vanthao03596
Hi guys, i follow jwt example in docs page. When token is expired graphql playgound show "error": "Unexpected token < in JSON at position 0". How i can handle this error ?
Idriz
@idrizp

Hi, was wondering as to why an empty array is translating into null when I query it?

    @Field(() => Comment, { nullable: true, defaultValue: [] })
    public comments?: Comment[];

I've debugged my resolver code, the comments is an empty array, not null, and yet graphql is sending null for it, any reason as to why?

5 replies
Nathan
@nspaeth

I am trying to return a union that includes an array:

export const Result = createUnionType({
  name: "Result",
  types: () => [Response, Errors.AlreadyExists, [Errors.Validation]],
})

But I am getting typescript errors saying that the types are incompatible. Is there a way to accomplish this?

6 replies
Oliver Salzburg
@oliversalzburg

I'm confused right now, because I have a test failure due to a validation in type-graphql that seems completely unrelated to the area of code I'm working on. Regardless, it seems like a real issue. The error is:

The 'created' field of 'SupportArchiveInput' has conflicting default values. Default value from decorator ('Thu Feb 18 2021 17:48:28 GMT+0100 (Central European Standard Time)') is not equal to the property initializer value ('Thu Feb 18 2021 17:48:29 GMT+0100 (Central European Standard Time)').

The field is defined as:

@GraphQL.Field(is => Date, {
  description: "When this support archive was created.",
})
@Validate.IsDate()
created = new Date();

I can see that the new Date() is potentially the issue here, but I don't quite understand why it's a problem and how to solve it.

14 replies
Maël Nison
@arcanis
is it possible to disable type analysis altogether, and require types to be set in each annotation? since I'm deploying the transpiled source code, the static analysis is actually detrimental, since the app may work locally and break in production
2 replies
vanthao03596
@vanthao03596

Hi guys, i follow jwt example in docs page. When token is expired graphql playgound show "error": "Unexpected token < in JSON at position 0". How i can handle this error ?

Can someone help me?

Maël Nison
@arcanis
Is there a way for a custom validation annotation to access the type-graphql context (similar to the @Ctx annotation)?
Maël Nison
@arcanis
(I'm asking this because I'm curious to know if one is supposed to build validation like @BookMustBelongToLoggedInUser(), or if such logic should be put in every query resolver)
4 replies
Tobi Taiwo
@rebirthtobi
AuthChecker always return status code 200 even when authentication change, how can I change this to 403
Kostiantyn Tkachenko
@astralian
Hey folks.
I try to manage ManyToMany relations, but something going wrong.
Could you please toss a glance little bit?
https://github.com/astralian/ic-server/blob/main/src/modules/post/post.entity.ts#L40
8 replies
Steve Gentile
@sgentile1_gitlab
this is most likely outside the scope of type-graphql, but I'm looking for examples of mocking out resolver calls for testing ?
mabilbao
@mabilbao

Hey guys! Thank you for this great project!
I started to use it yesterday and I really enjoy the experience. I have a really basic question:
I would like to implement a simple and abstract OrderBy class with 2 attributes: field (id, name, etc) and direction (asc, desc). I would like to implement a generic field to can show in each query which should be the fields allowed but I can not add a keyof into @Field. How should I implement this?

@InputType()
export class OrderBy<Type> {  
  @Field(type => String) -->   @Field(type => keyof Type) 
  field: keyof Type

  @Field(type => OrderByDirection)
  dir: OrderByDirection
}

Thank you :smile:

8 replies
Omar Dulaimi
@omar-dulaimi
This message was deleted
2 replies
Nathan
@nspaeth
Does anyone have any examples of more complex CustomScalarTypes? Is it possible to have other types be part of a CustomScalarType? For example, I would like to create an object type with arbitrary keys, but with typed values. I know that json-graphql-type exists, but that doesn't allow specifying the type of nested proprties.

Essentially, I'd like to represent the ts interface:

interface MyObject {
  [key: string]: MyGraphQLType
}

And have the nested types be properly checked.

Nathan
@nspaeth
Or even more generally:
interface AnyObject<T> {
   [key: string]: T
}
vidyaevoleg
@vidyaevoleg
Hi everyone!
I got a question regarding @Field( type => ) syntax.
I noticed that I can use the following syntax type => ID || [ID], but only IDgoes to schema (without the array of ID), so it doesn't declare that it also accepts <Array<ID>>.
How I can fix that?
One possible way is to create a custom scalar SingleOrArray.
How do you usually solve that, guys?
14 replies
Lewis Pham
@lewispham
Hi
I'm having troubles with integrating typegraphql with mercurius. The integration is ok until I need to add variables into request context.
Basically I can not extract a custom fastify request context via decorator @Ctx
    app.addHook("onRequest", async (request, reply) => {
        request.requestContext = {a: "some data"}
    });
Anybody know how to extract a custom request context within a resolver class?
6 replies
Steve Gentile
@sgentile1_gitlab
Does anyone have an example of testing a custom middleware with jest ? https://typegraphql.com/docs/middlewares.html
5 replies
Marco Correia
@marcovc
Hi! Is it possible to add a custom resolver written in javascript?
9 replies
Michał Lytek
@MichalLytek
:warning: STARTING FROM TODAY, GITTER WON'T BE USED ANYMORE AS A DISCUSSION PLATFORM FOR TYPEGRAPHQL :warning:
:warning: ALL THE QUESTIONS SHOULD BE PLACED ON THE GITHUB DISCUSSIONS PLATFORM :warning:
https://github.com/MichalLytek/type-graphql/discussions