Skip to content

Instantly share code, notes, and snippets.

@sogko
Last active November 11, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sogko/c763cd9fbc14d197a76e to your computer and use it in GitHub Desktop.
Save sogko/c763cd9fbc14d197a76e to your computer and use it in GitHub Desktop.
hello-world-relay-part-2 - Schema definition (golang)
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,
})
}
@se77en
Copy link

se77en commented Nov 11, 2016

where is the types come from at this line https://gist.github.com/sogko/c763cd9fbc14d197a76e#file-schema-go-L34 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment