-
-
Save adriancbo/0e899e309f4db26e626ab6113a99a535 to your computer and use it in GitHub Desktop.
graphql-tag fragment example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |
` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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