本文整理汇总了TypeScript中apollo-client.query函数的典型用法代码示例。如果您正苦于以下问题:TypeScript query函数的具体用法?TypeScript query怎么用?TypeScript query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fetchLastEventTime
async function fetchLastEventTime() {
updateLoading(true);
return apolloClient
.query<GetLastEventTimeQuery.Query, GetLastEventTimeQuery.Variables>({
query: LastEventTimeGqlQuery,
fetchPolicy: 'cache-first',
variables: {
sourceId,
indexKey,
details,
defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY),
},
})
.then(
result => {
updateLoading(false);
updateLastSeen(get('data.source.LastEventTime.lastSeen', result));
updateErrorMessage(null);
updateCurrentIndexKey(currentIndexKey);
return result;
},
error => {
updateLoading(false);
updateErrorMessage(error.message);
return error;
}
);
}
示例2: fetchFirstLastSeenHost
async function fetchFirstLastSeenHost() {
updateLoading(true);
return apolloClient
.query<GetHostFirstLastSeenQuery.Query, GetHostFirstLastSeenQuery.Variables>({
query: HostFirstLastSeenGqlQuery,
fetchPolicy: 'cache-first',
variables: {
sourceId,
hostName,
defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY),
},
})
.then(
result => {
updateLoading(false);
updateFirstSeen(get('data.source.HostFirstLastSeen.firstSeen', result));
updateLastSeen(get('data.source.HostFirstLastSeen.lastSeen', result));
updateErrorMessage(null);
return result;
},
error => {
updateLoading(false);
updateErrorMessage(error.message);
return error;
}
);
}
示例3: ApolloClient
.get('/oauth', async ctx => {
const { code, path, state } = ctx.query
if (!state || state !== ctx.session.uuid) {
return ctx.throw('invalid oauth redirect')
}
const { data } = await axios.post(
'https://github.com/login/oauth/access_token',
{
client_id: process.env.GITHUB_CLIENT_ID,
client_secret: process.env.GITHUB_CLIENT_SECRET,
code,
state,
},
{
headers: {
Accept: 'application/json',
},
},
)
if (data.error) {
return ctx.throw(data)
}
const token = data.access_token
ctx.session.token = token
const apollo = new ApolloClient({
link: createHttpLink({
uri: 'https://api.github.com/graphql',
headers: {
Authorization: `bearer ${token}`,
},
}),
cache: new InMemoryCache(),
})
const { data: user } = await apollo.query<{ viewer: User }>({
query: gql`
query {
viewer {
avatarUrl
id
login
name
url
websiteUrl
}
}
`,
})
ctx.session.user = user.viewer
ctx.redirect(`${path.replace(/ /g, '%2B')}`)
})