Gia
Code Helper Guide for "GraphQL in Action"
Listings
1.13
{
person(personID: 4) {
name
birthYear
homeworld {
name
}
filmConnection {
films {
title
}
}
}
}
2.9
{
viewer {
repositories(last: 10) {
nodes {
name
description
}
}
}
}
2.10
{
licenses {
name
url
}
}
2.11
{
repository(owner: "facebook", name: "graphql") {
issues(first: 10) {
nodes {
title
createdAt
author {
login
}
}
}
}
}
2.12
mutation {
addStar(input: {starrableId: "MDEwOlJlcG9zaXRvcnkzODM0MjIyMQ=="}) {
starrable {
stargazers {
totalCount
}
}
}
}
2.13
{
repository(name: "graphql", owner: "facebook") {
id
}
}
2.14
query GetIssueInfo {
repository(owner: "jscomplete", name: "graphql-in-action") {
issue(number: 1) {
id
title
}
}
}
2.15
mutation AddCommentToIssue {
addComment(input: {
subjectId: "MDU6SXNzdWUzMDYyMDMwNzk=",
body: "Hello GraphQL"
}) {
commentEdge {
node {
createdAt
}
}
}
}
2.16
{
__schema {
types {
name
description
}
}
}
2.17
{
__type(name: "Commit") {
fields {
name
args {
name
}
}
}
}
3.3
query OrgInfo {
organization(login: "jscomplete") {
name
description
websiteUrl
}
}
3.4
query First10Repos {
organization(login: "jscomplete") {
name
description
websiteUrl
repositories(first: 10) {
nodes {
name
}
}
}
}
3.5
query orgReposByName {
organization(login: "jscomplete") {
repositories(first:10, orderBy:{field: NAME, direction: ASC}) {
nodes {
name
}
}
}
}
3.6
query OrgPopularRepos {
organization(login: "jscomplete") {
repositories(first:10, orderBy:{field: STARGAZERS, direction: DESC}) {
nodes {
name
}
}
}
}
3.7
query OrgRepoConnectionExample {
organization(login: "jscomplete") {
repositories(first:10, orderBy:{field: STARGAZERS, direction: DESC}) {
edges {
cursor
node {
name
}
}
}
}
}
3.8
query OrgPopularReposPage2 {
organization(login: "jscomplete") {
repositories(
first: 10,
after: "Y3Vyc29yOnYyOpLNOE7OAeErrQ==",
orderBy: {field: STARGAZERS, direction: DESC}
) {
edges {
cursor
node {
name
}
}
}
}
}
3.9
query OrgReposMetaInfoExample {
organization(login: "jscomplete") {
repositories(
first: 10,
after: "Y3Vyc29yOnYyOpLNOE7OAeErrQ==",
orderBy: {field: STARGAZERS, direction: DESC}
) {
totalCount
pageInfo {
hasNextPage
}
edges {
cursor
node {
name
}
}
}
}
}
3.10
query SearchExample {
repository(owner: "twbs", name: "bootstrap") {
projects(search: "v4.1", first: 10) {
nodes {
name
}
}
}
}
3.11
query FilterExample {
viewer {
repositories(first: 10, affiliations: OWNER) {
totalCount
nodes {
name
}
}
}
}
3.12
mutation StarARepo {
addStar(input: {starrableId: "MDEwOlJlcG9zaXRvcnkzODM0MjIyMQ=="}) {
starrable {
stargazers {
totalCount
}
}
}
}
3.13
query ProfileInfo {
user(login: "samerbuna") {
name
company
bio
}
}
3.14
query ProfileInfoWithAlias {
user(login: "samerbuna") {
name
companyName: company
bio
}
}
3.15
query AllDirectives {
__schema {
directives {
name
description
locations
args {
name
description
defaultValue
}
}
}
}
3.16
query OrgInfo($orgLogin: String!) {
organization(login: $orgLogin) {
name
description
websiteUrl
}
}
3.17
query OrgInfoWithDefault($orgLogin: String = "facebook") {
organization(login: $orgLogin) {
name
description
websiteUrl
}
}
3.18
query OrgInfo($orgLogin: String!, $fullDetails: Boolean!) {
organization(login: $orgLogin) {
name
description
websiteUrl @include(if: $fullDetails)
}
}
3.19
query OrgInfo($orgLogin: String!, $partialDetails: Boolean!) {
organization(login: $orgLogin) {
name
description
websiteUrl @skip(if: $partialDetails)
}
}
3.20
query OrgInfo($orgLogin: String!, $partialDetails: Boolean!) {
organization(login: $orgLogin) {
name
description
websiteUrl @skip(if: $partialDetails) @include(if: false)
}
}
3.24
query MyRepos {
viewer {
ownedRepos: repositories(affiliations: OWNER, first: 10) {
nodes {
nameWithOwner
description
forkCount
}
}
orgsRepos: repositories(affiliations: ORGANIZATION_MEMBER, first: 10) {
nodes {
nameWithOwner
description
forkCount
}
}
}
}
3.25
query MyRepos {
viewer {
ownedRepos: repositories(affiliations: OWNER, first: 10) {
...repoInfo
}
orgsRepos: repositories(affiliations: ORGANIZATION_MEMBER, first: 10) {
...repoInfo
}
}
}
fragment repoInfo on RepositoryConnection {
nodes {
nameWithOwner
description
forkCount
}
}
3.34
query InlineFragmentExample {
repository(owner: "facebook", name: "graphql") {
ref(qualifiedName: "master") {
target {
... on Commit {
message
}
}
}
}
}
3.35
query RepoUnionExample {
repository(owner: "facebook", name: "graphql") {
issueOrPullRequest(number: 3) {
__typename
}
}
}
3.36
query RepoUnionExampleFull {
repository(owner: "facebook", name: "graphql") {
issueOrPullRequest(number: 5) {
... on PullRequest {
merged
mergedAt
}
... on Issue {
closed
closedAt
}
}
}
}
3.37
query TestSearch {
search(first: 100, query: "graphql", type: USER) {
nodes {
... on User {
name
bio
}
... on Organization {
login
description
}
}
}
}
Full API Schema
type Query {
currentTime: String
numbersInRange(begin: Int!, end: Int!): NumbersInRange
taskMainList: [Task!]
search(term: String!): [SearchResultItem!]
taskInfo(id: ID!): Task
me: Me
}
"""Aggregate info on a range of numbers"""
type NumbersInRange {
sum: Int!
count: Int!
}
type Task implements SearchResultItem {
id: ID!
createdAt: String!
content: String!
tags: [String!]!
approachCount: Int!
author: User!
approachList: [Approach!]!
}
interface SearchResultItem {
id: ID!
content: String!
}
type User {
id: ID!
email: String
name: String
createdAt: String!
}
type Approach implements SearchResultItem {
id: ID!
createdAt: String!
content: String!
voteCount: Int!
task: Task!
author: User!
detailList: [ApproachDetail!]!
}
type ApproachDetail {
content: String!
category: ApproachDetailCategory!
}
enum ApproachDetailCategory {
NOTE
EXPLANATION
WARNING
}
type Me {
id: ID!
username: String!
name: String
createdAt: String!
taskList: [Task!]!
}
type Mutation {
userCreate(input: UserInput!): UserPayload
userLogin(input: AuthInput!): UserPayload
taskCreate(input: TaskInput!): TaskPayload
approachCreate(taskId: ID!, input: ApproachInput!): ApproachPayload
approachVote(approachId: ID!, input: ApproachVoteInput!): ApproachPayload
}
type UserPayload {
errors: [UserError!]!
user: User
authToken: String
}
type UserError {
message: String!
}
input UserInput {
email: String!
password: String!
firstName: String
lastName: String
}
input AuthInput {
email: String!
password: String!
}
type TaskPayload {
errors: [UserError!]!
task: Task
}
input TaskInput {
content: String!
tags: [String!]!
isPrivate: Boolean!
}
type ApproachPayload {
errors: [UserError!]!
approach: Approach
}
input ApproachInput {
content: String!
detailList: [ApproachDetailInput!]!
}
input ApproachDetailInput {
content: String!
category: ApproachDetailCategory!
}
input ApproachVoteInput {
up: Boolean!
}
type Subscription {
voteChanged(taskId: ID!): Approach!
taskMainListChanged: [Task!]
}