github.com/roneli/gqlgen@v0.7.2/handler/stub.go (about)

     1  package handler
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/99designs/gqlgen/graphql"
     7  	"github.com/vektah/gqlparser"
     8  	"github.com/vektah/gqlparser/ast"
     9  )
    10  
    11  type executableSchemaStub struct {
    12  	NextResp chan struct{}
    13  }
    14  
    15  var _ graphql.ExecutableSchema = &executableSchemaStub{}
    16  
    17  func (e *executableSchemaStub) Schema() *ast.Schema {
    18  	return gqlparser.MustLoadSchema(&ast.Source{Input: `
    19  		schema { query: Query }
    20  		type Query {
    21  			me: User!
    22  			user(id: Int): User!
    23  		}
    24  		type User { name: String! }
    25  	`})
    26  }
    27  
    28  func (e *executableSchemaStub) Complexity(typeName, field string, childComplexity int, args map[string]interface{}) (int, bool) {
    29  	return 0, false
    30  }
    31  
    32  func (e *executableSchemaStub) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
    33  	return &graphql.Response{Data: []byte(`{"name":"test"}`)}
    34  }
    35  
    36  func (e *executableSchemaStub) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
    37  	return graphql.ErrorResponse(ctx, "mutations are not supported")
    38  }
    39  
    40  func (e *executableSchemaStub) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {
    41  	return func() *graphql.Response {
    42  		select {
    43  		case <-ctx.Done():
    44  			return nil
    45  		case <-e.NextResp:
    46  			return &graphql.Response{
    47  				Data: []byte(`{"name":"test"}`),
    48  			}
    49  		}
    50  	}
    51  }