Skip to content

Instantly share code, notes, and snippets.

@deptno
Created June 25, 2018 02:53
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deptno/e76d2550cfc0d374899c3e6efe5d7831 to your computer and use it in GitHub Desktop.
Save deptno/e76d2550cfc0d374899c3e6efe5d7831 to your computer and use it in GitHub Desktop.
graphql-tag fragment example
import gql from 'graphql-tag'
const FRAGMENT_REPOSITORY = gql`
fragment repository on Repository {
name
url
createdAt
description
descriptionHTML
labels {
totalCount
}
stargazers {
totalCount
}
watchers {
totalCount
}
forks {
totalCount
}
primaryLanguage {
name
color
}
owner {
login
}
}
`
export const FRAGMENT_REPOSITORY_CONNECTION = gql`
fragment repositoryConnection on RepositoryConnection {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
...repository
}
}
${FRAGMENT_REPOSITORY}
`
import gql from 'graphql-tag'
import {FRAGMENT_REPOSITORY_CONNECTION} from './fragment'
export const QUERY_USER = gql`
query getRepositories($userId: String!) {
user(login: $userId) {
login
createdAt
gists {
totalCount
}
organizations(first: 100) {
totalCount
nodes {
avatarUrl
name
}
}
repositories(privacy: PUBLIC, first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
...repositoryConnection
}
pinnedRepositories(first: 6) {
nodes {
...repository
}
}
}
}
${FRAGMENT_REPOSITORY_CONNECTION}
`
export const QUERY_REPOS_MORE = gql`
query getRepositoriesMore($userId: String!, $cursor: String) {
user(login: $userId) {
repositories(privacy: PUBLIC, after: $cursor, first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
...repositoryConnection
}
}
}
${FRAGMENT_REPOSITORY_CONNECTION}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment