Skip to content

Instantly share code, notes, and snippets.

@trevor-scheer
Created July 14, 2020 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevor-scheer/b6fbd0515345fe0e04f900201af58820 to your computer and use it in GitHub Desktop.
Save trevor-scheer/b6fbd0515345fe0e04f900201af58820 to your computer and use it in GitHub Desktop.
directive @stream on FIELD
directive @transform(from: String!) on FIELD
union AccountType = PasswordAccount | SMSAccount
type Amazon {
referrer: String
}
union Body = Image | Text
schema
@graph(name: "accounts", endpointUrl: "https://accounts.api.com")
@graph(name: "products", endpointUrl: "https://products.api.com")
@graph(name: "books", endpointUrl: "https://books.api.com")
@graph(name: "inventory", endpointUrl: "https://inventory.api.com")
@graph(name: "reviews", endpointUrl: "https://reviews.api.com")
@graph(name: "documents", endpointUrl: "https://documents.api.com")
@composedGraph(version: 1)
{
query: Query
mutation: Mutation
}
type Book implements Product
@owner(graph: "books")
@key(fields: "isbn", graph: "books")
@key(fields: "isbn", graph: "products")
@key(fields: "isbn", graph: "inventory")
@key(fields: "isbn", graph: "reviews")
{
isbn: String!
title: String
year: Int
similarBooks: [Book]!
metadata: [MetadataOrError]
upc: String! @resolve(graph: "products")
sku: String! @resolve(graph: "products")
name(delimeter: String = " "): String @resolve(graph: "products") @requires(fields: "title year")
price: String @resolve(graph: "products")
details: ProductDetailsBook @resolve(graph: "products")
inStock: Boolean @resolve(graph: "inventory")
isCheckedOut: Boolean @resolve(graph: "inventory")
reviews: [Review] @resolve(graph: "reviews")
relatedReviews: [Review!]! @resolve(graph: "reviews") @requires(fields: "similarBooks { isbn }")
}
union Brand = Ikea | Amazon
type Car implements Vehicle
@owner(graph: "products")
@key(fields: "id", graph: "products")
@key(fields: "id", graph: "reviews")
{
id: String!
description: String
price: String
retailPrice: String @resolve(graph: "reviews") @requires(fields: "price")
}
type Error {
code: Int
message: String
}
type Furniture implements Product
@owner(graph: "products")
@key(fields: "upc", graph: "products")
@key(fields: "sku", graph: "products")
@key(fields: "sku", graph: "inventory")
@key(fields: "upc", graph: "reviews")
{
upc: String!
sku: String!
name: String
price: String
brand: Brand
metadata: [MetadataOrError]
details: ProductDetailsFurniture
inStock: Boolean @resolve(graph: "inventory")
isHeavy: Boolean @resolve(graph: "inventory")
reviews: [Review] @resolve(graph: "reviews")
}
type Ikea {
asile: Int
}
type Image {
name: String!
attributes: ImageAttributes!
}
type ImageAttributes {
url: String!
}
type KeyValue {
key: String!
value: String!
}
type Library
@owner(graph: "books")
@key(fields: "id", graph: "books")
@key(fields: "id", graph: "accounts")
{
id: ID!
name: String
userAccount(id: ID! = 1): User @resolve(graph: "accounts") @requires(fields: "name")
}
union MetadataOrError = KeyValue | Error
type Mutation {
reviewProduct(upc: String!, body: String!): Product @resolve(graph: "reviews")
updateReview(review: UpdateReviewInput!): Review @resolve(graph: "reviews")
deleteReview(id: ID!): Boolean @resolve(graph: "reviews")
login(username: String!, password: String!): User @resolve(graph: "accounts")
}
type PasswordAccount
@owner(graph: "accounts")
@key(fields: "email")
{
email: String!
}
interface Product {
upc: String!
sku: String!
name: String
price: String
details: ProductDetails
inStock: Boolean
reviews: [Review]
}
interface ProductDetails {
country: String
}
type ProductDetailsBook implements ProductDetails {
country: String
pages: Int
}
type ProductDetailsFurniture implements ProductDetails {
country: String
color: String
}
type Query {
vehicle(id: String!): Vehicle @resolve(graph: "products")
product(upc: String!): Product @resolve(graph: "products")
topProducts(first: Int = 5): [Product] @resolve(graph: "products")
topCars(first: Int = 5): [Car] @resolve(graph: "products")
book(isbn: String!): Book @resolve(graph: "books")
books: [Book] @resolve(graph: "books")
library(id: ID!): Library @resolve(graph: "books")
body: Body! @resolve(graph: "documents")
topReviews(first: Int = 5): [Review] @resolve(graph: "reviews")
user(id: ID!): User @resolve(graph: "accounts")
me: User @resolve(graph: "accounts")
}
type Review
@owner(graph: "reviews")
@key(fields: "id", graph: "reviews")
{
id: ID!
body(format: Boolean = false): String
author: User @provides(fields: "username")
product: Product
metadata: [MetadataOrError]
}
type SMSAccount
@owner(graph: "accounts")
@key(fields: "number")
{
number: String
}
type Text {
name: String!
attributes: TextAttributes!
}
type TextAttributes {
bold: Boolean
text: String
}
union Thing = Car | Ikea
input UpdateReviewInput {
id: ID!
body: String
}
type User
@owner(graph: "accounts")
@key(fields: "id", graph: "accounts")
@key(fields: "id", graph: "products")
@key(fields: "id", graph: "inventory")
@key(fields: "id", graph: "reviews")
{
id: ID!
name: String
username: String
birthDate(locale: String): String
account: AccountType
metadata: [UserMetadata]
vehicle: Vehicle @resolve(graph: "products")
thing: Thing @resolve(graph: "products")
goodDescription: Boolean @resolve(graph: "inventory") @requires(fields: "metadata { description }")
reviews: [Review] @resolve(graph: "reviews")
numberOfReviews: Int! @resolve(graph: "reviews")
goodAddress: Boolean @resolve(graph: "reviews") @requires(fields: "metadata { address }")
}
type UserMetadata {
name: String
address: String
description: String
}
type Van implements Vehicle
@owner(graph: "products")
@key(fields: "id", graph: "products")
@key(fields: "id", graph: "reviews")
{
id: String!
description: String
price: String
retailPrice: String @resolve(graph: "reviews") @requires(fields: "price")
}
interface Vehicle {
id: String!
description: String
price: String
retailPrice: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment