refactor packages/graphql structure
This commit is contained in:
parent
5d8b2ffc6b
commit
5b996fbf68
@ -1,5 +1,5 @@
|
||||
import { env as environment } from './config/env';
|
||||
import { createCustomer, getCustomer } from '@repo/graphql/api/query';
|
||||
import { createCustomer, getCustomer } from '@repo/graphql/api';
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { message } from 'telegraf/filters';
|
||||
|
||||
|
||||
17
packages/graphql/api/auth.ts
Normal file
17
packages/graphql/api/auth.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { createApolloClient } from '../apollo/client';
|
||||
import { env as environment } from '../config/env';
|
||||
import * as GQL from '../types';
|
||||
|
||||
export async function login() {
|
||||
const { mutate } = createApolloClient();
|
||||
|
||||
const response = await mutate({
|
||||
mutation: GQL.LoginDocument,
|
||||
variables: {
|
||||
identifier: environment.LOGIN_GRAPHQL,
|
||||
password: environment.PASSWORD_GRAPHQL,
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
import { createApolloClient, getClientWithToken } from '../apollo/client';
|
||||
import { env as environment } from '../config/env';
|
||||
import { getClientWithToken } from '../apollo/client';
|
||||
import * as GQL from '../types';
|
||||
|
||||
export async function createCustomer(variables: GQL.CreateCustomerMutationVariables) {
|
||||
@ -19,17 +18,3 @@ export async function getCustomer(variables: GQL.GetCustomerQueryVariables) {
|
||||
variables,
|
||||
});
|
||||
}
|
||||
|
||||
export async function login() {
|
||||
const { mutate } = createApolloClient();
|
||||
|
||||
const response = await mutate({
|
||||
mutation: GQL.LoginDocument,
|
||||
variables: {
|
||||
identifier: environment.LOGIN_GRAPHQL,
|
||||
password: environment.PASSWORD_GRAPHQL,
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
2
packages/graphql/api/index.ts
Normal file
2
packages/graphql/api/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './auth';
|
||||
export * from './customer';
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-undef */
|
||||
module.exports = {
|
||||
client: {
|
||||
includes: ['../../packages/graphql/query.graphql'],
|
||||
includes: ['./operations/*.graphql'],
|
||||
service: {
|
||||
name: 'strapi',
|
||||
url: require('./config.cjs').url,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { login } from '../api/query';
|
||||
import { login } from '../api';
|
||||
import { isTokenExpired } from '../utils/jwt';
|
||||
|
||||
export const token: null | string = null;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/** @type {import('@graphql-codegen/cli').CodegenConfig} */
|
||||
module.exports = {
|
||||
documents: './query.graphql',
|
||||
documents: ['./operations/*.graphql'],
|
||||
generates: {
|
||||
'./types.ts': {
|
||||
'./types/operations.generated.ts': {
|
||||
config: {
|
||||
avoidOptionals: true,
|
||||
onlyOperationTypes: true,
|
||||
|
||||
14
packages/graphql/operations/auth.graphql
Normal file
14
packages/graphql/operations/auth.graphql
Normal file
@ -0,0 +1,14 @@
|
||||
mutation Register($identifier: String!, $password: String!, $email: String!) {
|
||||
register(input: { username: $identifier, password: $password, email: $email }) {
|
||||
jwt
|
||||
user {
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutation Login($identifier: String!, $password: String!) {
|
||||
login(input: { identifier: $identifier, password: $password }) {
|
||||
jwt
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,3 @@
|
||||
mutation Register($identifier: String!, $password: String!, $email: String!) {
|
||||
register(input: { username: $identifier, password: $password, email: $email }) {
|
||||
jwt
|
||||
user {
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutation Login($identifier: String!, $password: String!) {
|
||||
login(input: { identifier: $identifier, password: $password }) {
|
||||
jwt
|
||||
}
|
||||
}
|
||||
|
||||
mutation CreateCustomer($name: String!, $telegramId: Long!, $phone: String!) {
|
||||
createCustomer(data: { name: $name, telegramId: $telegramId, phone: $phone, role: client }) {
|
||||
documentId
|
||||
1
packages/graphql/types/index.ts
Normal file
1
packages/graphql/types/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './operations.generated';
|
||||
Loading…
x
Reference in New Issue
Block a user