Thank you very much for the content you are sharing. I’m fond of your videos; I never got the motivation to learn graphQL because of the whole new terminology to learn but now you got me motivated 😁
One of the best vids on this topic I've seen in the last couple of months ! Very educational. Thanks for willing to share your knowledge, and your time & effort to create this vid. Do you (or smb else) maybe have any idea how to implement one-to-many and many-to-many relations ? And how about Authentication ?
Hey Jens, thanks for the feedback! Unfortunately, this was just a quick one-off and is not part of a series. I do have some other graphql federation videos on my channel, however.
there is a strange behaviour in the code. If you put console.log in for example resolver function or service, the api endpoint is not returning response. So if you put console.log in getAllBooks resolver function and run books query from playground, it won't return any response (it's spinning and response isn't returned). If you remove the console.log, than there won't be any issue.
Hey Leo, I just deleted generated graphql.ts file, and my server runs with no error. Moreover, query & mutation are working correctly. So, what's the use of codegenerator here actually?
@@CodeDunks Thank you! I'm curently working on a project and was wondering if I could ask a few questions. Do you have discord maybe? Feel free to add me SlappTasken#8638
this code not works for me "305: Module '"apollo-server"' has no exported member 'makeExecutableSchema'. 1 import { gql, makeExecutableSchema } from 'apollo-server';"
Yeah seems there may have been a change in where it is imported from since when I made the video. www.apollographql.com/docs/apollo-server/migration/ You can do something like import { makeExecutableSchema } from '@graphql-tools/schema';
The reason for using Postgres over Mongo is due to MongoDB support being in early access for Prisma. www.prisma.io/docs/concepts/database-connectors/mongodb
Cool, but you don't really use the codegen here, hence why you can't figure out how to type the resolver input. And generating the schema is a bit convoluted. I only played a little bit with graphql and codegen but I came up with this instead: - I split my code into modules src/ and in each i have : --- .gql which is a raw GQL schema (eg: type Foo { id:String! } type Query { fooById(id: String): Foo }) --- a resolvers.ts that implements the needed resolvers for that gql Codegen is setup so it picks up all the gql files, plus some necessary mappings for Prisma, like so: overwrite: true schema: "./src/**/*.gql" documents: null generates: src/generated/graphql.ts: config: useIndexSignature: true contextType: "../context#Context" maybeValue: "T | undefined | null" mappers: Foo: "@prisma/client#Foo as PrismaFoo" scalars: DateTime: Date plugins: - "typescript" - "typescript-resolvers" Note: contextType maps to context.ts where for example: export interface Context { prisma: PrismaClient } Then all you need to do in each of your resolver.ts is to use the generated Resolvers type import { Resolvers } from '../generated/graphql' export const resolvers: Resolvers = { Query: { fooById: (_parent, args, context) => { return context.prisma.foo.findUnique({ where: { id: args.id || undefined }, }) }, }, } Then in my server.ts i recursively load all the gql into a schema and make it executable with the merge of all resolvers. So in that workflow you first write a GQL file, run generate that gets your type, then you can write your resolver automatically typed by the Resolvers type.
Hey Jeremy, this is awesome! I also appreciate the feedback on this. I agree that after getting to play around with this setup some more that I could have made a lot of things in this video a little bit clearer like the things you mentioned in this comment.
In almost all his videos, what this guy actually does is copy and paste the code from other forums like medium or something which other people have written. This guy barely knows what's actually happening and we can clearly see that while he explains things. Just spotted another fake UA-camr. This video too will be copied from somewhere else for sure !
Sweet video Leo! A good building block to build something more complex and a very nice introduction to graphql servers with TS. Nicely done!
Damned, i learned so much with this video. Thanks a lot !
Hey Leo, good to see you man! Cool stuff :)
Thank you very much for the content you are sharing. I’m fond of your videos; I never got the motivation to learn graphQL because of the whole new terminology to learn but now you got me motivated 😁
You got this!
I think it would be great to add request validation, error handling and JWT authorisation in this example repo for more completeness
One of the best vids on this topic I've seen in the last couple of months !
Very educational. Thanks for willing to share your knowledge, and your time & effort to create this vid.
Do you (or smb else) maybe have any idea how to implement one-to-many and many-to-many relations ?
And how about Authentication ?
The best content. I love it 🤩
it is great tutorial
and very clear
keep going
I was not expecting the "resolver testing is kind of a bitch sometimes", came out of nowhere XD
Lol my bad
@Leo Roese how to use custom scalar in your setup? or how to integrate it with graphql-scalars
U call also inject the services through context or datasources, like simple DI
Great video man!
What a great tutorial !!!! Just learning GQL and it's awesome. Is this video
part of series ?
Hey Jens, thanks for the feedback! Unfortunately, this was just a quick one-off and is not part of a series. I do have some other graphql federation videos on my channel, however.
Thank you so much 👍🏼🙏🎉
hey any prerequisites in understanding this video, ik react , js html and css
there is a strange behaviour in the code. If you put console.log in for example resolver function or service, the api endpoint is not returning response. So if you put console.log in getAllBooks resolver function and run books query from playground, it won't return any response (it's spinning and response isn't returned). If you remove the console.log, than there won't be any issue.
Hey Leo, I just deleted generated graphql.ts file, and my server runs with no error. Moreover, query & mutation are working correctly. So, what's the use of codegenerator here actually?
It’s just to generate typings to be used with typescript
Gracias por el video
Wonderful! Will you be federating these schemas as well?
Maybe if I ever get some free time but no plans as of right now. Thanks for watching!
I really like the theme you have for VsCode, which one is it? :)
Overall great video and I learned a lot, big thanks!
I use the dracula soft theme
@@CodeDunks Thank you!
I'm curently working on a project and was wondering if I could ask a few questions. Do you have discord maybe? Feel free to add me SlappTasken#8638
@@SmashieHC sure there is a discord server I just set up on my channel banner
this code not works for me "305: Module '"apollo-server"' has no exported member 'makeExecutableSchema'.
1 import { gql, makeExecutableSchema } from 'apollo-server';"
Yeah seems there may have been a change in where it is imported from since when I made the video. www.apollographql.com/docs/apollo-server/migration/
You can do something like
import { makeExecutableSchema } from '@graphql-tools/schema';
Why use Postgres over Mongo?
The reason for using Postgres over Mongo is due to MongoDB support being in early access for Prisma. www.prisma.io/docs/concepts/database-connectors/mongodb
@@CodeDunks That makes sense lol
"i trust myself i think" xD
you should defenitively checkout nexus graphql !!!
Cool, but you don't really use the codegen here, hence why you can't figure out how to type the resolver input. And generating the schema is a bit convoluted.
I only played a little bit with graphql and codegen but I came up with this instead:
- I split my code into modules src/ and in each i have :
--- .gql which is a raw GQL schema (eg: type Foo { id:String! } type Query { fooById(id: String): Foo })
--- a resolvers.ts that implements the needed resolvers for that gql
Codegen is setup so it picks up all the gql files, plus some necessary mappings for Prisma, like so:
overwrite: true
schema: "./src/**/*.gql"
documents: null
generates:
src/generated/graphql.ts:
config:
useIndexSignature: true
contextType: "../context#Context"
maybeValue: "T | undefined | null"
mappers:
Foo: "@prisma/client#Foo as PrismaFoo"
scalars:
DateTime: Date
plugins:
- "typescript"
- "typescript-resolvers"
Note: contextType maps to context.ts where for example:
export interface Context {
prisma: PrismaClient
}
Then all you need to do in each of your resolver.ts is to use the generated Resolvers type
import { Resolvers } from '../generated/graphql'
export const resolvers: Resolvers = {
Query: {
fooById: (_parent, args, context) => {
return context.prisma.foo.findUnique({
where: { id: args.id || undefined },
})
},
},
}
Then in my server.ts i recursively load all the gql into a schema and make it executable with the merge of all resolvers.
So in that workflow you first write a GQL file, run generate that gets your type, then you can write your resolver automatically typed by the Resolvers type.
Hey Jeremy, this is awesome! I also appreciate the feedback on this. I agree that after getting to play around with this setup some more that I could have made a lot of things in this video a little bit clearer like the things you mentioned in this comment.
so much boilerplates code...
I agree, was just trying to convey the typings for typescript but the tradeoffs are excessive haha.
In almost all his videos, what this guy actually does is copy and paste the code from other forums like medium or something which other people have written. This guy barely knows what's actually happening and we can clearly see that while he explains things. Just spotted another fake UA-camr. This video too will be copied from somewhere else for sure !
Stop being a hater, you probably don't know anything yourself.