Last active
June 14, 2016 19:07
-
-
Save taion/eb46f7b241ea9a4deb4373206e547f48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Post { | |
static Resource = HttpResource; | |
static resourceConfig = { endpoint: '/posts' }; | |
@field({ required: true })) | |
title = 'untitled'; | |
@field() | |
text = ''; | |
@field({ type: GraphQLInt }) | |
number; | |
@relationship(() => Author, { authorId: GraphQLString }, { required: True }) | |
author; | |
// Or maybe: | |
@field({ required: True })) | |
author = relationship(() => Author, { authorId: GraphQLString }); | |
@method({ input: GraphQLInt }, GraphQLInt) | |
square({ input }) { | |
return input * input; | |
} | |
// Not included on the GraphQL type. | |
propValue = 4; | |
static extraFields = () => ({ | |
extraField: { | |
type: GraphQLInt, | |
resolve: () => 3, | |
}, | |
}); | |
static mutations = [ | |
CreateMutation, | |
UpdatePartialMutation, | |
DeleteMutation, | |
]; | |
} | |
// So then when needed you could do: | |
Author.getResource(context) | |
Author.Type | |
Author.ConnectionType | |
// For a Relay server, you could do: | |
class Author extends NodeModel { /* ... */ } |
This file contains hidden or 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
// Imagine orm.Post is a Mongoose model or something equivalent. | |
class Post extends OrmModel(orm.Post) { | |
static fields = { | |
number: GraphQLInt, | |
propValue: null, // Or have a separate excludeFields? | |
// The rest get included by default. | |
} | |
// Maybe? | |
static methods = { | |
square: [{ input: GraphQLInt }, GraphQLInt], | |
} | |
static extraFields = () => ({ | |
extraField: { | |
type: GraphQLInt, | |
resolve: () => 3, | |
}, | |
}); | |
static mutations = [ | |
CreateMutation, | |
UpdatePartialMutation, | |
DeleteMutation, | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment