Skip to content

Commit

Permalink
Reclaim main package for public interface to code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Jan 10, 2019
1 parent 6b82903 commit f46b7c8
Show file tree
Hide file tree
Showing 43 changed files with 102 additions and 78 deletions.
2 changes: 1 addition & 1 deletion codegen/ambient.go → ambient.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codegen
package gqlgen

import (
// Import and ignore the ambient imports listed below so dependency managers
Expand Down
5 changes: 2 additions & 3 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/99designs/gqlgen/codegen"
"github.com/99designs/gqlgen"
"github.com/99designs/gqlgen/codegen/config"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand Down Expand Up @@ -36,8 +36,7 @@ var genCmd = cli.Command{
}
}

err = codegen.Generate(cfg)
if err != nil {
if err = gqlgen.Generate(cfg); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"os"
"strings"

"github.com/99designs/gqlgen/codegen"
"github.com/99designs/gqlgen"

"github.com/99designs/gqlgen/codegen/config"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand Down Expand Up @@ -70,12 +71,12 @@ var initCmd = cli.Command{
}

func GenerateGraphServer(cfg *config.Config, serverFilename string) {
err := codegen.Generate(cfg)
err := gqlgen.Generate(cfg)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}

if err := codegen.GenerateServer(serverFilename, cfg); err != nil {
if err := gqlgen.GenerateServer(serverFilename, cfg); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/build.go → codegen/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/types"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/build_bind.go → codegen/build_bind.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/ast"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/build_enum.go → codegen/build_enum.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/types"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/types"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/types"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/directive.go → codegen/directive.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/enum.go → codegen/enum.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

type Enum struct {
Definition *TypeDefinition
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/interface.go → codegen/interface.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

type Interface struct {
Definition *TypeDefinition
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/object.go → codegen/object.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/schema.go → codegen/schema.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"github.com/99designs/gqlgen/codegen/config"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/schema_test.go → codegen/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"testing"
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions codegen/testserver/generated_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//go:generate rm -f resolver.go
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package testserver

import (
"context"
"fmt"
"github.com/pkg/errors"
"net/http"
"net/http/httptest"
"reflect"
Expand All @@ -16,6 +15,8 @@ import (
"testing"
"time"

"github.com/pkg/errors"

"github.com/99designs/gqlgen/graphql/introspection"

"github.com/99designs/gqlgen/client"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/types"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/types"
Expand Down
2 changes: 1 addition & 1 deletion codegen/unified/util.go → codegen/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package unified
package codegen

import (
"go/build"
Expand Down
2 changes: 1 addition & 1 deletion codegen/codegen_test.go → codegen_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codegen
package gqlgen

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion example/chat/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package chat

Expand Down
2 changes: 1 addition & 1 deletion example/config/resolver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package config

Expand Down
2 changes: 1 addition & 1 deletion example/dataloader/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package dataloader

Expand Down
2 changes: 1 addition & 1 deletion example/scalars/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package scalars

Expand Down
5 changes: 5 additions & 0 deletions example/selection/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
schema: schema.graphql
model:
filename: models_gen.go
exec:
filename: generated.go
2 changes: 1 addition & 1 deletion example/selection/selection.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package selection

Expand Down
2 changes: 1 addition & 1 deletion example/starwars/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package starwars

Expand Down
2 changes: 1 addition & 1 deletion example/todo/todo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package todo

Expand Down
2 changes: 1 addition & 1 deletion example/type-system-extension/resolver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../../testdata/gqlgen.go

package type_system_extension

Expand Down
14 changes: 7 additions & 7 deletions codegen/exec.go → exec.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package codegen
package gqlgen

import (
"fmt"

"github.com/99designs/gqlgen/codegen"
"github.com/99designs/gqlgen/codegen/templates"
"github.com/99designs/gqlgen/codegen/unified"
)

type ExecBuild struct {
*unified.Schema
*codegen.Schema

PackageName string
QueryRoot *unified.Object
MutationRoot *unified.Object
SubscriptionRoot *unified.Object
QueryRoot *codegen.Object
MutationRoot *codegen.Object
SubscriptionRoot *codegen.Object
}

// bind a schema together with some code to generate a Build
func buildExec(s *unified.Schema) error {
func buildExec(s *codegen.Schema) error {
b := &ExecBuild{
Schema: s,
PackageName: s.Config.Exec.Package,
Expand Down
8 changes: 4 additions & 4 deletions codegen/generate.go → generate.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package codegen
package gqlgen

import (
"path/filepath"
"syscall"

"github.com/99designs/gqlgen/codegen"
"github.com/99designs/gqlgen/codegen/config"
"github.com/99designs/gqlgen/codegen/unified"
"github.com/pkg/errors"
)

func Generate(cfg *config.Config) error {
_ = syscall.Unlink(cfg.Exec.Filename)
_ = syscall.Unlink(cfg.Model.Filename)

schema, err := unified.NewSchema(cfg)
schema, err := codegen.NewSchema(cfg)
if err != nil {
return errors.Wrap(err, "merging failed")
}
Expand All @@ -23,7 +23,7 @@ func Generate(cfg *config.Config) error {
}

// Merge again now that the generated models have been injected into the typemap
schema, err = unified.NewSchema(schema.Config)
schema, err = codegen.NewSchema(schema.Config)
if err != nil {
return errors.Wrap(err, "merging failed")
}
Expand Down
2 changes: 1 addition & 1 deletion integration/resolver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/99designs/gqlgen
//go:generate go run ../testdata/gqlgen.go

package integration

Expand Down
7 changes: 3 additions & 4 deletions internal/imports/testdata/unused.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package testdata

import "unused"
import _ "underscore"
import a "fmt"
import "time"
Expand All @@ -14,8 +13,8 @@ func fn() {
}

type Message struct {
ID string `json:"id"`
Text string `json:"text"`
CreatedBy string `json:"createdBy"`
ID string `json:"id"`
Text string `json:"text"`
CreatedBy string `json:"createdBy"`
CreatedAt time.Time `json:"createdAt"`
}
13 changes: 0 additions & 13 deletions main.go

This file was deleted.

12 changes: 6 additions & 6 deletions codegen/model.go → model.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package codegen
package gqlgen

import (
"sort"

"go/types"

"github.com/99designs/gqlgen/codegen"
"github.com/99designs/gqlgen/codegen/templates"
"github.com/99designs/gqlgen/codegen/unified"
)

type ModelBuild struct {
Interfaces []*unified.Interface
Models unified.Objects
Enums []unified.Enum
Interfaces []*codegen.Interface
Models codegen.Objects
Enums []codegen.Enum
PackageName string
}

// Create a list of models that need to be generated
func buildModels(s *unified.Schema) error {
func buildModels(s *codegen.Schema) error {
b := &ModelBuild{
PackageName: s.Config.Model.Package,
}
Expand Down
Loading

0 comments on commit f46b7c8

Please sign in to comment.