Skip to content
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

Use shared prelude #204

Merged
merged 1 commit into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions codegen/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Build struct {
MutationRoot *Object
SubscriptionRoot *Object
SchemaRaw string
SchemaFilename string
}

type ModelBuild struct {
Expand Down Expand Up @@ -76,12 +77,13 @@ func (cfg *Config) bind() (*Build, error) {
}

b := &Build{
PackageName: cfg.Exec.Package,
Objects: objects,
Interfaces: cfg.buildInterfaces(namedTypes, prog),
Inputs: inputs,
Imports: imports.finalize(),
SchemaRaw: cfg.SchemaStr,
PackageName: cfg.Exec.Package,
Objects: objects,
Interfaces: cfg.buildInterfaces(namedTypes, prog),
Inputs: inputs,
Imports: imports.finalize(),
SchemaRaw: cfg.SchemaStr,
SchemaFilename: cfg.SchemaFilename,
}

if cfg.schema.Query != nil {
Expand Down
12 changes: 8 additions & 4 deletions codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

"github.com/pkg/errors"
"github.com/vektah/gqlgen/codegen/templates"
"github.com/vektah/gqlgen/graphql/introspection"
"github.com/vektah/gqlparser"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/gqlerror"
"golang.org/x/tools/imports"
)

Expand Down Expand Up @@ -107,9 +108,12 @@ func (cfg *Config) normalize() error {
}
}

var err error
cfg.schema, err = gqlparser.LoadSchema(introspection.Prelude + cfg.SchemaStr)
return err
var err *gqlerror.Error
cfg.schema, err = gqlparser.LoadSchema(&ast.Source{Name: cfg.SchemaFilename, Input: cfg.SchemaStr})
if err != nil {
return err
}
return nil
}

var invalidPackageNameChar = regexp.MustCompile(`[^\w]`)
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/data.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion codegen/templates/generated.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,6 @@ func (ec *executionContext) introspectType(name string) *introspection.Type {
return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name])
}

var parsedSchema = gqlparser.MustLoadSchema(introspection.Prelude + {{.SchemaRaw|rawQuote}})
var parsedSchema = gqlparser.MustLoadSchema(
&ast.Source{Name: {{.SchemaFilename|quote}}, Input: {{.SchemaRaw|rawQuote}}},
)
3 changes: 3 additions & 0 deletions codegen/type_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (n NamedTypes) getType(t *ast.Type) *Type {
if !t.NonNull {
modifiers = append(modifiers, modPtr)
}
if n[t.NamedType] == nil {
panic("missing type " + t.NamedType)
}
res := &Type{
NamedType: n[t.NamedType],
Modifiers: modifiers,
Expand Down
6 changes: 4 additions & 2 deletions example/chat/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions example/dataloader/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions example/scalars/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions example/selection/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions example/starwars/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions example/todo/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions example/todo/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ input TodoInput {
text: String!
done: Boolean
}

scalar Map
31 changes: 0 additions & 31 deletions graphql/introspection/inliner/inliner.go

This file was deleted.

2 changes: 0 additions & 2 deletions graphql/introspection/introspection.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:generate go run ./inliner/inliner.go

// introspection implements the spec defined in https://github.com/facebook/graphql/blob/master/spec/Section%204%20--%20Introspection.md#schema-introspection
package introspection

Expand Down
3 changes: 0 additions & 3 deletions graphql/introspection/prelude.go

This file was deleted.

96 changes: 0 additions & 96 deletions graphql/introspection/prelude.graphql

This file was deleted.

4 changes: 2 additions & 2 deletions handler/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type executableSchemaStub struct {
var _ graphql.ExecutableSchema = &executableSchemaStub{}

func (e *executableSchemaStub) Schema() *ast.Schema {
return gqlparser.MustLoadSchema(`
return gqlparser.MustLoadSchema(&ast.Source{Input: `
schema { query: Query }
type Query { me: User! }
type User { name: String! }
`)
`})
}

func (e *executableSchemaStub) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
Expand Down
6 changes: 4 additions & 2 deletions test/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.