-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update field collection to allow inline fragment without type (#3384)
* init new defer example * restructure example as flat, update gqlgen.yml * update resolver to return data * re-implement field collection for inline fragment to always test if the fragment type applies first and that this test only happens if there is a fragment type defined * remove superfluous field collection wrappers and simplify test format * add tests; replicate logic for fragment spreads * remove optional type fragment for spreads * now that we've excised them from tests, re-introduce field collection helpers * re-introduce collect all tests * lint * add back in context helpers to example * make explanatory comments read easier and remove unnecessary changes
- Loading branch information
1 parent
0d2ba68
commit be20ed5
Showing
10 changed files
with
4,471 additions
and
28 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
schema: "*.graphql" | ||
|
||
exec: | ||
filename: generated.go | ||
|
||
model: | ||
filename: models_gen.go | ||
|
||
resolver: | ||
layout: follow-schema | ||
dir: . | ||
filename_template: "{name}.resolvers.go" | ||
|
||
call_argument_directives_with_null: true | ||
|
||
models: | ||
ID: | ||
model: | ||
- github.com/99designs/gqlgen/graphql.ID | ||
Todo: | ||
fields: | ||
user: | ||
resolver: true | ||
extraFields: | ||
userID: | ||
type: "string" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package deferexample | ||
|
||
import "sync" | ||
|
||
type Resolver struct { | ||
mu sync.RWMutex | ||
todos []*Todo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# GraphQL schema example | ||
# | ||
# https://gqlgen.com/getting-started/ | ||
|
||
type Todo { | ||
id: ID! | ||
text: String! | ||
done: Boolean! | ||
user: User! | ||
} | ||
|
||
type User { | ||
id: ID! | ||
name: String! | ||
} | ||
|
||
type Query { | ||
todos: [Todo!]! | ||
} | ||
|
||
input NewTodo { | ||
text: String! | ||
userId: String! | ||
} | ||
|
||
type Mutation { | ||
createTodo(input: NewTodo!): Todo! | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/99designs/gqlgen/_examples/deferexample" | ||
"github.com/99designs/gqlgen/graphql/handler" | ||
"github.com/99designs/gqlgen/graphql/handler/extension" | ||
"github.com/99designs/gqlgen/graphql/handler/transport" | ||
"github.com/99designs/gqlgen/graphql/playground" | ||
"github.com/gorilla/websocket" | ||
"github.com/rs/cors" | ||
) | ||
|
||
const defaultPort = "8080" | ||
|
||
func main() { | ||
port := os.Getenv("PORT") | ||
if port == "" { | ||
port = defaultPort | ||
} | ||
|
||
c := cors.New(cors.Options{ | ||
AllowedOrigins: []string{"*"}, | ||
AllowCredentials: true, | ||
Debug: false, | ||
}) | ||
|
||
srv := handler.New( | ||
deferexample.NewExecutableSchema( | ||
deferexample.Config{Resolvers: &deferexample.Resolver{}}, | ||
), | ||
) | ||
|
||
srv.AddTransport(transport.SSE{}) | ||
srv.AddTransport(transport.MultipartMixed{ | ||
Boundary: "graphql", | ||
DeliveryTimeout: time.Millisecond * 10, | ||
}) | ||
srv.AddTransport(transport.POST{}) | ||
srv.AddTransport(transport.Websocket{ | ||
KeepAlivePingInterval: 10 * time.Second, | ||
Upgrader: websocket.Upgrader{ | ||
CheckOrigin: func(r *http.Request) bool { | ||
return true | ||
}, | ||
}, | ||
}) | ||
srv.Use(extension.Introspection{}) | ||
|
||
http.Handle("/", playground.Handler("Todo", "/query")) | ||
http.Handle("/query", c.Handler(srv)) | ||
|
||
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port) | ||
log.Fatal(http.ListenAndServe(":"+port, nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.