本文整理汇总了TypeScript中graphql-request.GraphQLClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLClient类的具体用法?TypeScript GraphQLClient怎么用?TypeScript GraphQLClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphQLClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createGraphcoolUser
async function createGraphcoolUser(
api: GraphQLClient,
email: string,
password: string,
): Promise<string> {
const mutation = `
mutation createGraphcoolUser($email: String!, $password: String!) {
createUser(
email: $email,
password: $password
) {
id
}
}
`;
const variables = {
email,
password: password,
};
return api
.request<{ createUser: User }>(mutation, variables)
.then(r => r.createUser.id);
}
示例2: getUser
async function getUser(api: GraphQLClient, email: string): Promise<{ User }> {
const query = `
query getUser($email: String!) {
User(email: $email) {
id
}
}
`;
const variables = {
email,
};
return api.request<{ User }>(query, variables);
}
示例3: getUser
async function getUser(api: GraphQLClient, id: string): Promise<{ User }> {
const query = `
query getUser($id: ID!) {
User(id: $id) {
id
}
}
`
const variables = {
id,
}
return api.request<{ User }>(query, variables)
}
示例4: require
import Deploy from './deploy'
import { changedDefaultDefinition } from '../../examples'
import { mockDefinition, Config } from 'prisma-cli-engine'
import default_definition from './nocks/default_definition'
import local_instance from './nocks/local_instance'
import { MockGraphQLClient } from '../../test/mock-client'
jest.mock('graphql-request')
const GraphQLClient = require('graphql-request').GraphQLClient
GraphQLClient.mockImplementation(MockGraphQLClient)
const mockEnv = {
stages: {
default: 'dev',
dev: 'cj8be5ct201is0140cq7qp23b',
},
}
const localMockEnv = {
clusters: {
default: 'local',
local: {
token:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MDcwMjM3NzMsImNsaWVudElkIjoiY2o4YTAxZHN1MDAwMDAxMjM1aWF1aTFoYiJ9.WscmbACu0HqPEDSk_U66TNOskGddmt2plJAew6XCyNw',
host: 'http://localhost:4466',
},
},
}
describe.skip('deploy', () => {
test('from empty to default definition', async () => {
示例5: authenticateUser
async authenticateUser (accessToken: string): Promise<AuthenticatedUser> {
const mutation = `
mutation ($accessToken: String!) {
authenticateUser(
accessToken: $accessToken
) {
id
token
email
}
}
`
return this.client.request<{ authenticateUser: AuthenticatedUser }>(mutation, { accessToken })
.then((response) => response.authenticateUser)
}
示例6: getDatabases
async getDatabases(): Promise<string[]> {
const result = await this.client.request<any>(
`{
__type(name: "PrismaDatabase") {
kind
enumValues {
name
}
}
}`,
)
if (result && result.__type && result.__type.enumValues) {
return result.__type.enumValues.map(v => v.name)
}
return []
}
示例7: getRecipients
async getRecipients (userId: string): Promise<[Recipient]> {
const query = `
query ($userId: ID!) {
allRecipients(filter: {
user: {
id: $userId
}
}) {
id
tags
phoneNumber
name
createdAt
}
}
`
return this.client.request<{allRecipients: [Recipient]}>(query, { userId })
.then((response) => response.allRecipients)
}
示例8: getDocReviewDate
docNames.subscribe(x => {
let key = path.basename(x, ".md");
if (!srcData[key])
return;
let vars = {
"path": "lib/" + srcData[key].path
};
client.request(query, vars).then(data => {
let nodes = data["repository"].ref.target.history.nodes;
let lastReviewDate = getDocReviewDate(x);//(key + ".md");
let numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist);
let dateString = lastReviewDate.format("YYYY-MM-DD");
let score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3);
console.log(`'${key}','${dateString}','${numUsefulCommits}','${score}'`);
});
});
示例9: query
async query(query: string, variables: string[] = []): Promise<any> {
const finalQuery = this.replace(query, variables)
const databases = await this.getDatabases()
if (!databases || !databases[0]) {
throw new Error(`Prisma Config doesn't have any database connection`)
}
return this.client.request(
`
mutation executeRaw($query: String! $database: PrismaDatabase) {
rows: executeRaw(
database: $database
query: $query
)
}
`,
{
query: finalQuery,
database: databases[0],
},
)
}
示例10: async
const gqlRequest = async (request: string, variables: any) => {
return await graphQLClient.request(request, variables)
}