Last active
November 11, 2016 08:59
-
-
Save sogko/c763cd9fbc14d197a76e to your computer and use it in GitHub Desktop.
hello-world-relay-part-2 - Schema definition (golang)
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 data | |
import ( | |
"github.com/graphql-go/graphql" | |
"github.com/graphql-go/relay" | |
) | |
var postType *graphql.Object | |
var queryType *graphql.Object | |
var Schema graphql.Schema | |
func init() { | |
postType = graphql.NewObject(graphql.ObjectConfig{ | |
Name: "Post", | |
Fields: graphql.Fields{ | |
// Define `id` field as a Relay GlobalID field. | |
// It helps with translating your GraphQL object's id into a global id | |
// For eg: | |
// For a `Post` type, with an id of `1`, it's global id will be `UG9zdDox` | |
// which is a base64 encoded version of `Post:1` string | |
// We will explore more in the next part of this series. | |
"id": relay.GlobalIDField("Post", nil), | |
"text": &graphql.Field{ | |
Type: graphql.String, | |
}, | |
}, | |
}) | |
queryType = graphql.NewObject(graphql.ObjectConfig{ | |
Name: "Query", | |
Fields: graphql.Fields{ | |
"latestPost": &graphql.Field{ | |
Type: postType, | |
Resolve: func(p types.ResolveParams) interface{} { | |
return GetLatestPost() | |
}, | |
}, | |
}, | |
}) | |
Schema, _ = graphql.NewSchema(graphql.SchemaConfig{ | |
Query: queryType, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where is the
types
come from at this line https://gist.github.com/sogko/c763cd9fbc14d197a76e#file-schema-go-L34 ?