Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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