-
Notifications
You must be signed in to change notification settings - Fork 842
API Improvement. #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Woah the improvements starting to look good 👍🏻 My humble notes: 1. Resolve function
helloResolve := func(p graphql.ResolveParams) (interface{}, error) {
return "world", nil
} 2. graphql.Fields, graphql.FieldThis is definitely a much need improvement (i.e. renaming In the proposed example, it is a How about we retain it as map? Because the field key and the field name can be different. package graphql
type Field struct
type Fields map[string]*Field
...
package example
fields := graphql.Fields{
"hello": &graphql.Field{Name: "Hello Field", Type: graphql.String, Resolve: helloResolve},
} 3. graphql.NewSchema() and root queryAt first glance, the new
func main() {
helloResolve := func(p graphql.ResolveParams) interface{} {
return "world"
}
queryFields := graphql.Fields{
"hello": graphql.Field{Name: "Hello Field", Type: graphql.String, Resolve: helloResolve},
}
rootQuery := graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: queryFields,
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{Query: rootQuery})
// or with mutation,
// schema, err := graphql.NewSchema(graphql.SchemaConfig{Query: rootQuery, Mutation: mutationQuery})
if err != nil {
log.Fatalf("failed to create new schema, error: %v", err)
}
...
} 4. Constructor configsI wish we can get rid of the config structs for the constructor. There is some hope; there is a proposal for named arguments to be added to the language golang/go#12296 and golang/go#12854, but realistically, it would take awhile. 5. graphql.Do()I'm in favour of this over the current Cheers! |
I think that
is a very complicated interface. As far as I can tell, there's no need for the result channel at all (everything in the executor appears to be synchronous), but if it is required then it'd be nice for
would be my ideal interface. |
I also prefer the Do syntax. |
Definitely looking forward to more robust error handling and less |
Hi @sogko I would like to get support on custom error reporting as #74 I can think of two approaches
This is explained by @sogko above
tradeoff I prefer option 1 and being explicit. I can work on this if you all agree. Cheers, |
@chris-ramon @sogko any comment on error handling. currently the framework is catching panic and suppressing the cause of error. I keep hitting this as Iost context information make it hard to track down an error. Please give some priority on this. |
Right now what I do is comment out the defers and recovers in executor.go that really helps and crashes your server a lot. But then that is only for development. We are actually planning to make a graphql implementation using code generation for performance in the future. |
@pyros2097 with code generation? tell us more :) |
By we I mean my company. Well we have 3 Type systems one was our postgres types, then go types and then graphql types. So to map go types to postgres types and tables we had done it using code generation using go generate. But didn't have time to do it for graphql types also. So say you have a struct type User struct {
ID string `json:"id"`
name string `json:"id"`
} we had to manually create a graphql type for each struct and that was a bit painful as we already know what types ID and name were and even needed to create custom scalar types for validation like PLPassword(which I think should be done in Go and on the struct). So you techincally wouldn't need to create all graphql types, maybe you might only need to resolve the fields. And another thing we found out was that a lot of reflection was used for serialization and de-serialization and the current graphql implementation we need to resolve interfaces or map[string]interfaces{} which can be improved if you know the type you need to json encode. @atrniv Any word on the implementation you were talking about? (PS He is the code generation guy you can look at all his projects they all have code generation in them even the js ones ) |
@pyros2097 thanks for the tip. that helps :-) |
@chris-ramon you rock :-) I can see the effort you putting in this. tx. |
adds query and mutation tests to check error from is being handled
adds query and mutation test to check correct returning error from
adds query and mutation test to check correct returning error from graphql.FieldResolveFn
executor does handle potential errors for executing graphql.FieldResolveFn
@pkieltyka We have implemented it and using it on our live servers you can check the tests out although there is no documentation whatsoever ... https://github.com/playlyfe/go-graphql |
Let's close this one; and have a new conversation on API improvements on new issues, thanks a lot for bringing great ideas guys 👍 🌟 |
Before releasing the first version of the lib, I think we could improve the API, meaning remove verbosity and clean-it-up to be go-idiomatic, so please do share ur thoughts on this! 👍
This is the basic example from the
Getting Started
section onREADME
(still to merge #43):My initial proposal is:
The text was updated successfully, but these errors were encountered: