Last active
November 1, 2017 00:56
-
-
Save jakubfiala/cb37ce8cde5c122f8d1a5b3be0da7060 to your computer and use it in GitHub Desktop.
Example of creating data schemae using Google's protocol buffers and Facebook's GraphQL Schema Language
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
# this defines a new field type | |
scalar HTML | |
# this defines a new object type | |
type Institution { | |
# the ! denotes a required field | |
name: String! | |
location: String | |
} | |
type Person { | |
full_name: String! | |
# [] denote a list, as opposed to a single value | |
institutions: [Institution] | |
biography: HTML | |
job_title: String | |
photo_url: String | |
} | |
type Project { | |
title: String! | |
description: HTML | |
institutions: [Institution] | |
} | |
type Scheme { | |
title: String! | |
} | |
union GrantHolder = [Person] | Project | |
type Grantee { | |
holder: GrantHolder! | |
scheme: Scheme! | |
award_amount: Float | |
year_awarded: Int | |
} | |
# this defines our actual public schema, e.g. the types we can use from it | |
schema { | |
grantee: Grantee | |
grant_holder: GrantHolder | |
person: Person | |
scheme: Scheme | |
institution: Institution | |
project: Project | |
html: HTML | |
} |
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
syntax = "proto3"; | |
message HTML { | |
string content = 1; | |
} | |
message Institution { | |
string name = 1; | |
string location = 2; | |
} | |
message Person { | |
string full_name = 1; | |
repeated Institution institutions = 2; | |
HTML biography = 3; | |
string job_title = 4; | |
string photo_url = 5; | |
} | |
message Project { | |
string title = 1; | |
string description = 2; | |
repeated Institution institutions = 3; | |
} | |
message Scheme { | |
string title = 1; | |
} | |
message Grantee { | |
oneof holder { | |
Person person = 1; | |
Project project = 2; | |
} | |
Scheme scheme = 3; | |
uint32 award_amount = 4; | |
uint32 year_awarded = 5; | |
} |
@ephemer - This is proto3 version, which no longer has required
or optional
qualifiers on the field declarations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should
Institution
(and others) have arequired
field in the protobuf definitions?