2021/10/28
JAMJAMJAMStack/Online #2
export const searchQuery = gql`
query {
viewer {
login
repository(name: "ohayo-developers") {
createdAt
name
issues(last: 100 orderBy: { field: CREATED_AT, direction: DESC }) {
nodes {
id
body
createdAt
title
url
number
labels(last: 10) {
nodes {
id
name
}
}
timelineItems(first: 10) {
nodes {
... on IssueComment {
id
body
}
}
}
participants(last: 10) {
nodes {
id
login
name
avatarUrl(size: 40)
}
}
}
}
}
}
}
`
export const searchQuery = gql`
query {
viewer {
login
repository(name: "ohayo-developers") {
issues(last: 100 orderBy: { field: CREATED_AT, direction: DESC }) {
nodes {
timelineItems(first: 10) {
nodes {
... on IssueComment {
id
body
}
}
}
}
}
}
}
}
`
{
"__schema": {
"types": [
{
"kind": "UNION",
"name": "IssueComment",
"possibleTypes": [
{
"name": "IssueComment"
}
]
}
]
}
}
import fetch from 'isomorphic-unfetch'
import ApolloClient from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { ApolloLink, concat } from 'apollo-link'
import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'
import introspectionQueryResultData from './fragmentTypes.json'
const GITHUB_API_V4 = 'https://api.github.com/graphql'
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData
})
const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
Authorization: `bearer ${
import.meta.env.VITE_APP_GITHUB_API_ACCESS_TOKEN
}`,
Accept: 'application/vnd.github.v4.idl'
}
})
return forward(operation)
})
const httpLink = new HttpLink({
uri: GITHUB_API_V4,
fetch
})
export const apolloClient = new ApolloClient({
link: concat(authMiddleware, httpLink),
cache: new InMemoryCache({
fragmentMatcher
})
})
import { useQuery, useResult } from '@vue/apollo-composable'
import { searchQuery } from '../graphql/issue'
export default {
setup() {
const { result, error, loading } = useQuery(searchQuery)
const issues = useResult(
result,
null,
(data) => data.viewer.repository?.issues?.nodes
)
return { loading, error, issues }
}
}