This example is meant to show a full implementation of the server using an SQL datastore.
Starting
start the server, if you don't have the sqlite library already installed from gorm, then it
may take a while to compile it
go run *.go
and then visit the GraphiQL dev server at localhost:8080
NOTES:
int32 maps to the graphql type Int, so if a number is desired, int32 must be used
there are data structs for database models, and there is another struct that is usually
in the form of...
type FooResolver struct {
db *DB
m Foo
}
authentication could go in middleware in the server part
authorization could be done with middleware, or from the user in the context after
authentication in either the db methods or the resolvers. Official graphql recommends
that these go into the data layer, but if a per-field authorization is needed, the field
resolvers are the perfect place.
edges, connections, used for pagination
there is a type
it has a connection, which is another type that it is connected to
the connection happens through an edge which represents the relationship
Example queries
get user by ids with pets belonging to the user...
请发表评论