-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
"Getting Started" docs seem pretty broken? #773
Comments
@dvelitchkov Same error here. Got any solution? |
I think there is also a typo with the Todos resolver.
instead of
|
@als9xd I think you may have commented on the wrong issue buddy. I can replicate the issue too, looks like something to do with how the default config already has the directives fields set and is used to unmarshal the local config here: https://github.com/99designs/gqlgen/blob/master/codegen/config/config.go#L36 Which was added in 17a82c3 by @lwc Rolling back to an earlier version before May 27th may work due to removing this change, but will unfortunately roll back a load of other additions. Simple reproduction here: https://play.golang.org/p/vFVkfwFpCTk From the Yaml docs: "UnmarshalStrict is like Unmarshal except that any fields that are found in the data that do not have corresponding struct members, or mapping keys that are duplicates, will result in an error." Shows that this would never work. Should probably add those keys in to the default config only for writing the initial or if they are not found AFTER parsing the local gqlgen.yml |
not sure why this was closed. i am very familiar with graphql but new to go. wanted to learn how its implemented on the go side and was recommended gqlgen. i am appreciative of your tool and guide. but i hope that given a complete beginner perspective we can improve the docs. if you can sort me out id be happy to open a PR with fixes to improve it for future beginners this is a list of my own confusions: Create the database models
Next tell gqlgen to use this new struct by adding it to gqlgen.yml: models:
Todo:
model: github.com/[username]/gqlgen-todos.Todo my own # .gqlgen.yml example
#
# Refer to https://gqlgen.com/config/
# for detailed .gqlgen.yml documentation.
schema:
- schema.graphql
exec:
filename: generated.go
model:
filename: models_gen.go
# there is no models field so i added it here
models:
Todo:
model: github.com/the-vampiire/gqlgen-todos.Todo
resolver:
filename: resolver.go
type: Resolver
autobind: []
directives:
deprecated:
skip_runtime: true
include:
skip_runtime: true
skip:
skip_runtime: true i then ran the following commands: $ vim gqlgen.yml
$ go run github.com/99designs/gqlgen
unable to parse config: yaml: unmarshal errors:
line 21: key "deprecated" already set in map
line 23: key "include" already set in map
line 25: key "skip" already set in map
exit status 2 using what i saw from OP i commented out the directives bit and then ran using the $ vim gqlgen.yml
$ go run github.com/99designs/gqlgen -v
/Users/vampiire/codes/personal/gqlgen-todos/todo.go:3 adding resolver method for Todo.user, nothing matched
Skipped resolver: /Users/vampiire/codes/personal/gqlgen-todos/resolver.go already exists since this is not working, instead of creating a |
so the warning about "nothing matched" and "skipped resolver" did not have an impact. i continued with the rest of the guide and it worked. maybe just clarify those beginning parts because the rest seems to be correct. thanks |
In Go everything in the package can be spread over many files in the same directory. So todo.go should be placed in the same directory as models_gen.go. I would not recommend modifying models_gen.go, just move it out. The model field should be your the full package + struct type i think (more of a go packages thing). |
good to know man thank you for the information. if its not too much to ask i was trying to implement a little extension to the code so cement my understanding. i added the following mutation to the schema type Mutation {
completeTodo(todoID: ID!): Todo
} then in my edit: im dumb. in go types come after the var name!
func (r *mutationResolver) CompleteTodo(ctx context.Context, todoID string) (*Todo, error) {
for _, todo := range r.todos {
if todo.ID == todoID {
todo.Done = true
return todo, nil
}
}
return nil, nil
}
|
another curiosity i have is why the schema uses lowercase but in the go code all the properties are capitalized. is this a go convention for structs or something to do with the lib itself? |
In Go lowercase properties are private banks uppercase are exported I.e. public |
is that a convention (like |
deconstructing the code it looks like adding "methods" (not sure of terminology in go) onto a struct has the form func (*this StructName) FuncName(args) returnType | (returnType, returnType2) {
// implementation
// this refers to the instance of the struct for accessing properties in the method
} anyways this was pretty cool thank you for the guide. i think i will spend some time learning go now! |
I submitted PR #801 to address a few of the inconsistencies, but I still get these errors:
I see that #781 appears to address this, but I don't get the benefit. Do I need to do something to get this update? |
This issue of |
Why issue was closed? The issue still exists:
|
It seems that just change from Related Issue: #781 |
Still getting this error when following the getting started tutorial. Removing the following lines from directives:
deprecated:
skip_runtime: true
include:
skip_runtime: true
skip:
skip_runtime: true |
I'm still having this error
So I have switched it to
|
What happened?
Multiple steps seem broken/missing
The tutorial tells you to define your own "getting started" schema - https://gqlgen.com/getting-started/#define-the-schema - then to run
go run github.com/99designs/gqlgen init
. Defining your own schema is completely pointless becauseinit
will just drop one in for you.Ok, so far so good. Got my stuff in place. Second problem - need to enable "lazy loading" for the User model in the Todo model (sorry if my terminology is off, a bit new to graphql)
So I change
to
Ok then it says to run
go run github.com/99designs/gqlgen
and proceeds to tell me about the "verbose" flag which isn't even in the command I just ran (?) But let's ignore that and rungqlgen
without any parameters which is the same as running it with thegenerate
command (probably mention that?)Ouch? At this point, all I've done is changed the User entity a bit and I'm getting yaml unmarshal errors? Ok let's remove the offending keys (why is the default
gqlgen.yml
causing errors?)Finally - success. So is the expected workflow for me to comment out the directives every time I run generate?
So to sum up:
What did you expect?
Stuff to mostly work.
Minimal graphql.schema and models to reproduce
Default from
init
commandversions
gqlgen version
- v0.9.1go version
? - 1.12.6 darwin/amd64The text was updated successfully, but these errors were encountered: