Skip to content

Instantly share code, notes, and snippets.

@adriancbo
Forked from deptno/fragment.ts
Created July 14, 2019 19:54
Show Gist options
  • Save adriancbo/0e899e309f4db26e626ab6113a99a535 to your computer and use it in GitHub Desktop.
Save adriancbo/0e899e309f4db26e626ab6113a99a535 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