Comments (4)
It took me a while to find how to do it but this is how I did it.
How to
In the /graphql/types
folder add a file named DateTime.ts
and put this in it
// /graphql/types/DateTime.ts
import { GraphQLScalarType } from "graphql";
import { DateTimeResolver } from "graphql-scalars";
import { asNexusMethod } from "nexus";
export const DateTime = asNexusMethod(
new GraphQLScalarType(DateTimeResolver),
"dateTime"
);
then in /graphql/types/index.ts
export it like so
// /graphql/types/index.ts
export * from "./DateTime";
This makes it so that when Nexus generates schema.graphql
it adds the DateTime type to the mix and outputs this somewhere in it
### /graphql/schema.graphql
"""
A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.
"""
scalar DateTime
Now whenever you need to add a date in your Nexus definitions you can do it like this
// /graphql/types/Course.ts
// Imports...
export const Course = objectType({
name: "Course",
definition(t) {
t.nonNull.id("id");
t.nonNull.dateTime("createdAt");
t.nonNull.dateTime("updatedAt");
// Other stuff...
},
});
// More stuff...
and the schema.graphql
output as expected will look like this:
### /graphql/schema.graphql
type Course {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
### Other stuff
}
Documentation
There's not one single place where you can find this nor one single way to do it.
Nexus has an adoption guide for Nexus framework users and in the bundled-scalars section you can find what I used.
Notes
Keep in mind that you will need to add the graphql-scalars
package to your dependencies
I hope this helps you
from awesome-links.
I hope this helps you
Just thanks, it's working like a charm.
I will go through the documentation you linked to understand how it's working !
Keep in mind that you will need to add the graphql-scalars package to your dependencies
Just went to : https://github.com/prisma/nexus-prisma/blob/main/package.json
And noticed they use "graphql-scalars" so we are doomed to use it anyway xD
I must understand what a scalar is now ;)
I'm gonna close this issue later, if i don't encounter any bug
from awesome-links.
Thanks for the reply @milovangudelj !!
from awesome-links.
And noticed they use "graphql-scalars" so we are doomed to use it anyway xD
Not necessairly, a dependency of a package you install does not translate to a dependency in your project. If you want to use it you still need to install it.
Just thanks, it's working like a charm.
I'm glad to hear that 😊
from awesome-links.
Related Issues (15)
- [Question] Missing blog posts HOT 2
- Incorrect import in part-1 HOT 2
- Typescript intellense not working HOT 1
- Property 'connectionField' does not exist on type 'ObjectDefinitionBlock<"Query">' HOT 3
- GraphQL Queries fail after any changes HOT 1
- Does this tutorial use cursor or offset navigation? HOT 1
- Can't query from Apollo Studio after Part 3 HOT 3
- Are the old branches available? HOT 1
- Set up Renovate
- ReferenceError: prisma is not defined
- Runtime error on part-3 branch: Cannot read properties of undefined (reading 'Symbol(Pothos.contextCache)') HOT 1
- High vulnerabilities: XSS in Image Optimization API for Next.js HOT 1
- Nexus and ApolloServer types discrepancy HOT 4
- Part 3? :) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome-links.