modulepackage
0.0.0-20231012004527-77189e400b6e
Repository: https://github.com/dagger/graphql-go-tools.git
Documentation: pkg.go.dev
# README
graphql-go-tools
Like apollo-tools for graphql-go
Current Tools
MakeExecutableSchema
Currently supports:
- Merge multiple graphql documents
- Object type extending
- Custom Directives
- Import types and directives
Planned:
- Schema-stitching
Limitations:
- Only types and directives defined in the
TypeDefs
with schema language can be extended and have custom directives applied.
Example
func main() {
schema, err := tools.MakeExecutableSchema(tools.ExecutableSchema{
TypeDefs: `
directive @description(value: String!) on FIELD_DEFINITION
type Foo {
id: ID!
name: String!
description: String
}
type Query {
foo(id: ID!): Foo @description(value: "bazqux")
}`,
Resolvers: tools.ResolverMap{
"Query": &tools.ObjectResolver{
Fields: tools.FieldResolveMap{
"foo": &tools.FieldResolver{
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
// lookup data
return foo, nil
}
},
},
},
},
SchemaDirectives: tools.SchemaDirectiveVisitorMap{
"description": &tools.SchemaDirectiveVisitor{
VisitFieldDefinition: func(field *graphql.Field, args map[string]interface{}) {
resolveFunc := field.Resolve
field.Resolve = func(p graphql.ResolveParams) (interface{}, error) {
result, err := resolveFunc(p)
if err != nil {
return result, err
}
data := result.(map[string]interface{})
data["description"] = args["value"]
return data, nil
}
},
},
},
})
if err != nil {
log.Fatalf("Failed to build schema, error: %v", err)
}
params := graphql.Params{
Schema: schema,
RequestString: `
query GetFoo {
foo(id: "5cffbf1ccecefcfff659cea8") {
description
}
}`,
}
r := graphql.Do(params)
if r.HasErrors() {
log.Fatalf("failed to execute graphql operation, errors: %+v", r.Errors)
}
rJSON, _ := json.Marshal(r)
fmt.Printf("%s \n", rJSON)
}
Handler
Modified graphql-go/handler
with updated GraphiQL and Playground
See handler package
# Functions
Prepares an object map of argument values given a list of argument definitions and list of argument AST nodes.
GetPathFieldSubSelections gets the subselectiond for a path.
MakeExecutableSchema is shorthand for ExecutableSchema{}.Make(ctx context.Context).
MakeExecutableSchemaWithContext make a schema and supply a context.
Merges object definitions.
ReadSourceFiles reads all source files from a specified path.
UnaliasedPathArray gets the path array for a resolve function without aliases.
# Constants
default root type names.
default root type names.
default root type names.
No description provided by the author
# Variables
HideDirective hides a define field.
# Structs
EnumResolver config for enum values.
ExecutableSchema configuration for making an executable schema this attempts to provide similar functionality to Apollo graphql-tools https://www.apollographql.com/docs/graphql-tools/generate-schema.
FieldResolve field resolver.
InterfaceResolver config for interface resolve.
ObjectResolver config for object resolver map.
ScalarResolver config for a scalar resolve map.
SchemaDirectiveVisitor defines a schema visitor.
UnionResolver config for interface resolve.
VisitArgumentDefinitionParams params.
VisitEnumParams params.
VisitEnumValueParams params.
VisitFieldDefinitionParams params.
VisitInputFieldDefinitionParams params.
VisitInputObjectParams params.
VisitInterfaceParams params.
VisitObjectParams params.
VisitScalarParams params.
VisitSchemaParams params.
VisitUnionParams params.
# Interfaces
Resolver interface to a resolver configuration.
# Type aliases
No description provided by the author
DirectiveMap a map of directives.
FieldResolveMap map of field resolve functions.
ResolverMap a map of resolver configurations.
SchemaDirectiveVisitorMap a map of schema directive visitors.