GraphQL Nexus - adding custom scalar type - Stack Overflow
What do you think about nexus? I'm new at this and wondering if I should use it in my project.
🚀Weekly Discussion: GraphQL SDL/TypeGraphQL/Graphql Nexus✨
I'm currently using type-graphql and there's 3 things I really like about it:
Works well with Typescript
You can use database models as GraphQL types when paired with TypeORM
You can programmatically generate GraphQL types/resolvers
I've tried GraphQL Nexus and I think it might have more potential. The type inference is better, #2 can be achieved with Prisma, and it uses objects/functions which are easier to programmatically create than classes. It does feel a little more verbose to write, but not by much.
More on reddit.com🚀Using GraphQL Nexus with a Database
great article and explanation! it really drives me to convert our graphql-yoga + prisma schema first setup to graphql-nexus
More on reddit.comI just finished the State of Graphql survey and the Schema Builders questions got me thinking if I shouldn't be using Nexus? I'm not a huge fan of the errors or the API to write custom types. I'm also using Prisma, so it feels like I'm typing out my types twice every time I add a query or a mutation.
It's okay, but is there a better option? What's your favorite? Why?
These were the options in the survey:
-
Nexus
-
TypeGraphQL
-
Pothos
-
Strawberry
-
Sangria
-
gqlgen
-
Graphql Zeus
-
Genql
-
Graphql Code Generator
You can also do this:
t.field("data", {type: "JSON"});
That works perfectly fine with TypeScript. And I wish they had better examples and documentation. Their examples only cover the most trivial use cases. I'm getting very heavily into GraphQL, Prisma, Nexus and related tool for a huge data set. So I'm literally hitting every limitation and lack of documentation that exists.
But alas we can pool our knowledge here.
To resolve this issue what I did was: 1. once you create your own scalar type such as:
#json.ts **FILE NAME MATTERS**
export const JSONScalar = scalarType({
name: "JSON",
asNexusMethod: "json",
description: "JSON scalar type",
...})
2. Once I called the new type in a separate object I had to add this above my field for it to compile, you may not have too:
//@ts-ignore
t.topjson("data");
3. In my make schema I added the scalar code first:
const schema = makeSchema({
types: [JSONScalar, MyObject, BlahObject],
The name of the file is very important I think that is how the schema is generated and looks for the new type. I also think you have to be sure to compile that code first in the makeSchema however I did not try to switch around the order as I spent a lot of time trying to figure out how to make my own scalar type work.
This may have been self explanatory for more seasoned Nexus developers however I am a novice so these steps escaped me.
Happy coding!
Hi! I'm building a project with next.js/prisma/apollo/graphql/typescript stack. I'm relatively new at this stuff, but I'm determined to learn all these technologies.
I keep seeing examples of people using nexus along with this stack, but I don't entirely understand the value it adds. On one hand, I don't need yet another unfamiliar tech to deal with, on another, if it makes things better/easier somehow, I'd do it.
Could someone ELI5 this for me? Should I be learning it and using it in my project?