refactor packages/graphql structure

This commit is contained in:
vchikalkin 2024-12-23 19:55:58 +03:00
parent 5d8b2ffc6b
commit 5b996fbf68
11 changed files with 40 additions and 36 deletions

View File

@ -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';

View 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;
}

View File

@ -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;
}

View File

@ -0,0 +1,2 @@
export * from './auth';
export * from './customer';

View File

@ -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,

View File

@ -1,4 +1,4 @@
import { login } from '../api/query';
import { login } from '../api';
import { isTokenExpired } from '../utils/jwt';
export const token: null | string = null;

View File

@ -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,

View 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
}
}

View File

@ -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

View File

@ -0,0 +1 @@
export * from './operations.generated';