I'm about to start using this library for a project for my company, but I'm not sure about two things..
query getUsers {
users {
id
name
posts(numberOfPosts: 5) {
id
title
text
}
}
}
query getUsers {
users {
id
name
posts(numberOfPosts: 5) {
id
title
text
}
}
}
One would not need to SELECT *, but SELECT user.id, user.name but also post.id, post.name, post.text.
I think we can get field from context but how could know which field is a scalar and which is not ?
Thanks in advance for answering my questions.
This is going to depend a little bit on how you're mapping to your User and Post models, but in general if in your schema you add an argument to a field, you will get given a resolver to implement.
type User {
posts(numberOfPosts: Int!): [Post!]!
}
The above schema will generate a resolver interface that looks something like:
func (r *userResolver) Posts(ctx context.Context, u *User, numberOfPosts int) ([]Post, error) {
// TODO retrieve numberOfPosts Posts for User from DB
}
For your second question, it depends on how you're fetching from your database in the resolver. To get access to the set of collected fields, you can call graphql.CollectFieldsCtx() and inspect the returned []CollectedField for the columns you require.
20ms for the request duration with this simple query : query getCustomers {
customers {
id
name
orders {
id
date
amount
items {
name
}
}
}
}
Is this not too much, knowing that there is not a lot of data ?
It's difficult to say whether this is a long time or not without more information on the size of your dataset, how you've implemented your resolvers etc. I would suggest doing some profiling to get a sense of where you're spending your time, ensuring you have your dataloader well configured etc. We do have an open tracing middleware that might be of use.
This is going to depend a little bit on how you're mapping to your
UserandPostmodels, but in general if in your schema you add an argument to a field, you will get given a resolver to implement.type User { posts(numberOfPosts: Int!): [Post!]! }The above schema will generate a resolver interface that looks something like:
func (r *userResolver) Posts(ctx context.Context, u *User, numberOfPosts int) ([]Post, error) { // TODO retrieve numberOfPosts Posts for User from DB }For your second question, it depends on how you're fetching from your database in the resolver. To get access to the set of collected fields, you can call
graphql.CollectFieldsCtx()and inspect the returned[]CollectedFieldfor the columns you require.
Hi, I just realized it doesn't work like that. The Posts resolver doesn't get generated, are you it is implemented yet ?
@Daavidaviid Is right , I have something similar to query using input variables and I dont see a resolver being generated . Although I could see some type generated related to the input variables
@mathewbyrne , i have got similar thing but gqlgen does not generate anything about the Post resolver as your comments. Please confirm this.
Most helpful comment
Hi, I just realized it doesn't work like that. The Posts resolver doesn't get generated, are you it is implemented yet ?