Permalink
Browse files

Initial draft of readme

  • Loading branch information...
Jonas Helfer
Jonas Helfer committed Mar 22, 2016
0 parents commit fe17783a6a166278195d172beb5670b045fb300d
Showing with 189 additions and 0 deletions.
  1. 0 .gitignore
  2. +83 −0 README.md
  3. +106 −0 test/discourse-api/schema.gql
No changes.
@@ -0,0 +1,83 @@
# A GraphQL proxy that uses graphql-js

MVP for a GraphQL proxy. Initially nothing more than a GraphQL server.

This GraphQL proxy is built on
* express
* graphql-js
* graphql-shorthand-parser


## How to use:

Apollo-proxy takes two inputs:
1. A GraphQL schema in shorthand format
1. One or more javascript code files that define resolve functions

An example of a valid GraphQL shorthand input:
```
type Book {
id: ID!
title: String!
genre: Genre
author: Author
}
interface Person {
firstName: String!
lastName: String
middleName: String
}
type Author: Person {
id: ID!
firstName: String!
lastName: String
middleName: String
booksPublished: [Book]
}
enum Genre {
FICTION
NONFICTION
}
type RootQuery {
author(id: ID!): Author,
book(title: String!): Book
}
type RootMutation {
addBook(title: String!, genre: Genre!, author_id: ID): Book
}
```

The corresponding file that defines how fields are resolved. If a field does not
have a resolve function, it is assumed to be the standard resolve function.
```
import DB from "DB.js";
export const {
Book: {
_resolve: id => DB.Books.get(id), // this function gets called as Book
author: (book, _, _) => Author(book.author_id),
// fields without resolve function just return book.<fieldName>
},
Author: {
_resolve: id => DB.Authors.get(id),
booksPublished: (author, _, _) => DB.Books.list( {author_id: author.id}),
},
RootQuery: {
author: (_, { id }, _) => Author(id),
book: (_, { title }, _) => DB.Books.getByTitle(title),
},
RootMutation: {
addBook: (_, { title, genre, author_id }, _) => {
return DB.createBook( {title: title, genre: genre, author_id: author_id});
},
},
}
```
@@ -0,0 +1,106 @@
// A discourse Post
type Post {
id: Int
created_at: String
cooked: String
updated_at: String
reply_count: Int
reads: Int
score: Int
version: Int
can_edit: Boolean
can_delete: Boolean
can_recover: Boolean
can_wiki: Boolean
raw: String
wiki: Boolean
user_id: Int
category_id: Int
topic: Topic
}

// A discourse Topic
type Topic {
id: Int
title: String
fancy_title: String
posts_count: Int
views: Int
reply_count: Int
participant_count: Int
like_count: Int
visible: Boolean
closed: Boolean
archived: Boolean
has_summary: Boolean
slug: String
word_count: Int
user_id: Int
draft_key: String
draft_sequence: String
category: Category
}

// A discource Category
type Category {
id: Int
name: String
color: String
text_color: String
slug: String
topic_count: Int
post_count: Int
position: Int
description: Int
read_restricted: Boolean
can_edit: Boolean
auto_close_based_on_last_post: Boolean
cannot_delete_reason: String
latest_topics: PaginatedTopicList
new_topics: PaginatedTopicList
}

//A paginated list of discourse topics
type PaginatedTopicList {
pages(page: Int numPages: Int): [TopicListPage]
}

//One page of discourse topics
type TopicListPage {
topics: [Topic]
}

//Enum of time periods used in Discourse queries
enum TimePeriod {
ALL
YEARLY
QUARTERLY
MONTHLY
WEEKLY
DAILY
}

//Authenticated type for root query
type AuthenticatedQuery {
allPosts: [Post]
allTopics: [Topic]
allCategories: [Category]

onePost: Post
oneTopic: Topic
oneCategory: Category

latest: PaginatedTopicList
unread: PaginatedTopicList
new: PaginatedTopicList
top(period: TimePeriod): PaginatedTopicList
}

type Query {
root(token: String!): AuthenticatedQuery
}

//Mutation used for logging in to Discourse
type Mutation {
login(username: String! password: String!): String
}

0 comments on commit fe17783

Please sign in to comment.