-
Notifications
You must be signed in to change notification settings - Fork 842
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
Naming #20
Comments
Hi @bsr203 Thanks a lot for taking your time to look into this 👍🏻 Struct names for GraphQL typesI do agree with you that currently the API is pretty verbose. @chris-ramon and I had a discussion previously about the package and type names in PR #16. Seems like all of us are on the same page about having a more concise API, which is great! I don't think anyone has started on working on it yet. Getters method namesRegarding the getters, it gets a bit tricky, because those are interface methods, for e.g. So for e.g, currently, type GraphQLType interface {
GetName() string
GetDescription() string
GetError() error
String() string
}
type GraphQLAbstractType interface {
GetObjectType(value interface{}, info GraphQLResolveInfo) *GraphQLObjectType
GetPossibleTypes() []*GraphQLObjectType
IsPossibleType(ttype *GraphQLObjectType) bool
} And types that implement it, for e.g. type GraphQLInterfaceType struct {
Name string `json:"name"`
Description string `json:"description"`
ResolveType ResolveTypeFn
}
// implements `GraphQLType` interface
func (it *GraphQLInterfaceType) GetDescription() string {}
func (it *GraphQLInterfaceType) GetError() error {}
func (it *GraphQLInterfaceType) GetName() string {}
// implements `GraphQLAbstractType` interface
func (it *GraphQLInterfaceType) GetObjectType(value interface{}, info GraphQLResolveInfo) {}*GraphQLObjectType
func (it *GraphQLInterfaceType) GetPossibleTypes() []*GraphQLObjectType {} What we have right nowSo in practice, what we have currently is the following:
var node types.GraphQLInterfaceType
...
name := node.Name // access field directly, you can even set it.
name2 := node.GetName() // or you can choose to access the field from its interface method.
resolveFn := node.ResolveFn // exported field specific to `GraphQLInterfaceType`
var node types.GraphQLType
...
name := node.GetName() // access the field from its interface method. Considering an alternate
|
@sogko thanks for the kind words and the detailed analysis. I couldn't agree with you guys more on the discussion https://github.com/chris-ramon/graphql-go/pull/16 and really likes what @chris-ramon suggests. I am not sure I like the name change from
IMHO it is hard to read About getters, I like to keep the struct field private and use method to access it. One reason, in go we always use single letter to note the receiver, so typically we may write like
It also depends on how frequently we use it though. In the Also in the main package, do we really need to use the acronym Similarly not so sure about |
One of the proposals is to bring import (
"github.com/chris-ramon/graphql-go"
)
blogSchema, err := gql.NewSchema(&gql.Schema{
Query: gql.NewObjectType(&gql.ObjectType{
...
}),
}) What do you think about that direction?
I also think
I wrote both I did at one point of time wondered if it would make better sense for handler := gql.NewHandler()
or
handler := graphql.NewHandler() But then again, apart from the naming, currently there are parallels with GraphQL's Javascript ecosystem:
Anyone else want to share their thoughts in this? Would love to hear more voice and opinions 👍🏻 /cc @chris-ramon |
Great conversation about better pkg naming within the lib! really appreciate your thoughts 🌟 Currently we have Also is great timing to share thoughts about have a better library API for As @sogko pointed out, (graphql-go) -> $GOPATH/bin/deplist github.com/chris-ramon/graphql-go/types
github.com/chris-ramon/graphql-go/language/visitor
github.com/chris-ramon/graphql-go/errors
github.com/chris-ramon/graphql-go/language/ast
github.com/chris-ramon/graphql-go/language/kinds
github.com/chris-ramon/graphql-go/language/source
github.com/chris-ramon/graphql-go/language/location
github.com/chris-ramon/graphql-go/language/printer
Meaning all the files from those packages should be move to After doing that plus fixing the current import (
"github.com/chris-ramon/graphql-go"
)
blogSchema, err := gql.NewSchema(&gql.Schema{
Query: gql.NewObjectType(&gql.ObjectType{
...
}),
}) Being the current API: import (
"github.com/chris-ramon/graphql-go"
"github.com/chris-ramon/graphql-go/types"
)
blogSchema, err := types.NewGraphQLSchema(types.GraphQLSchemaConfig{
Query: types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
...
}),
}) Said that, import (
"github.com/chris-ramon/graphql-go"
"github.com/chris-ramon/graphql-go/gt"
)
blogSchema, err := gt.NewSchema(>.Schema{
Query: gt.NewObjectType(>.ObjectType{
...
}),
}) |
What about this convention:
import (
"github.com/chris-ramon/graphql-go"
)
query := graphql.NewObject(...)
mutation := graphql.NewObject(...)
schema, err := graphql.NewSchema(query, mutation) |
@chris-ramon I too like everything to be under "graphql-go". I was saying, if one doesn't like like the name, they could alias it, but definitely like "gql". Thanks for the giving a momentum to this. |
Thanks a lot for sharing ur thoughts! - really appreciate it! 🌟 I would like it to summarize this issue to the following todos, if you have any final suggestions please do share.
|
Very good summary! In a second thought, the |
+1 for the todos . Thanks for your effort. |
Thanks for sharing ur thoughts on this @lenaten, I think we should remove Interfaces:
Structs:
Function constructors:
Special cases*:
For special cases* I think we should prefer rename to the shortest name the ones that will be use by lib users to build their graphql schemas, eg:
|
OK, let's do it! |
Updates on this issue:
Cheers! |
Great! Are you going to replace the import paths to |
Yup!, I'll submit a PR in a bit. |
Import paths replaced on this PR. |
hi.. shall we close this, and track the minor ones separate like #64 there are few more under
|
I think the general rename went well, but one thing I don't understand is why some things adopted certain naming patterns but others didn't. For example, we now have While I generally think the rename has gone really well thus far I think there is still places that can be approved on. |
… from here for perf-related PRs. - simple hello world equivalent - with a list - deeper query with list - query with many root fields and list in each of them - deeper query with many root fields and lists To really bring out probable issues with query perf, a latency is introduced to the data retrieval (previously it was just in-memory data fetch) When testing against branch before PR #20 and #21, this really highlighted the problem with evaluating list fields. In the future, more benchmarks for queries with fragments probably would be useful.
I am just starting with the library and my comments may be premature. I haven't touched Go for an year now, so not sure the community has changed their view on conventions. But I found the naming is bit verbose, and add noise.
If I look at the types, we know the context is
GraphQL type
, so not sure we need to attachGraphQL
to everythingas we don't need to add the data type it holds to.
Also quickly looking through the doc
typically you don't prefix the getters with
Get
, so they will be likeDescription(), Error() , Name()
, or may even export the fields.Let me know yours and @sogko 's thoughts on this. I could try a PR for if you agree.
thanks
bsr.
The text was updated successfully, but these errors were encountered: