Created
January 6, 2016 00:46
-
-
Save chris-ramon/53116f19d9fea6d024d5 to your computer and use it in GitHub Desktop.
graphql go new api
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
// | |
package main | |
import ( | |
"log" | |
"github.com/graphql-go/graphql" | |
) | |
type Schema struct { | |
Hello string | |
} | |
func (s *Schema) Query() graphql.Resolver { | |
return graphql.Resolve{ | |
"hello": helloResolveFn, | |
} | |
} | |
func (s *Schema) Mutation() graphql.Resolver { | |
return graphql.Resolve{} | |
} | |
func helloResolveFn(p graphql.ResolveParams) (interface{}, error) { | |
return "World", nil | |
} | |
func main() { | |
query := `{ hello }` | |
params := graphql.Params{Schema: &Schema, Query: query} | |
r, err := graphql.Do(params) | |
if err != nil { | |
log.Printf("failed to do graphql operation, error: %v", err) | |
return | |
} | |
log.Printf("graphql result: %v", r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment