0

good I have a problem and I looked but I can't find

Well, the problem is that I would like to have a dynamic field in my GraphQL Type, the value of this field depends on the other fields if one of the other fields becomes true then the value of this field increases

need help with this problem

2 Answers 2

1

If you're using type-graphql, you could use FieldResolver for something like that, e.g.

UserType.ts

...
@Field(() => String)
firstName: string

@Field(() => String)
lastName: string

UserResolver.ts

...
@FieldResolver(() => String)
public fullName(@Root() userType: UserType): string {
    return `${userType.firstName} ${userType.lastName}`
}

This will create dynamic field fullName based on firstName and lastName, so you can use this analogy to create your own logic.

Sign up to request clarification or add additional context in comments.

Comments

0

GraphQL is not dynamic. You can either define multiple queries or add a custom scalar that will have a type like any.

It is somewhat a shame, but it will only allow you static types with no conditions. The only dynamic part is that you can decide what you want to download and what not. Trust me, I looked for it too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.