mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08:00
refactor(server): e2e utilities (#11000)
This commit is contained in:
3
packages/common/graphql/README.md
Normal file
3
packages/common/graphql/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# `GraphQL` client
|
||||
|
||||
Auto generated `GraphQL` client for affine.pro
|
||||
34
packages/common/graphql/codegen.yml
Normal file
34
packages/common/graphql/codegen.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
hooks:
|
||||
afterOneFileWrite:
|
||||
- prettier --write
|
||||
config:
|
||||
strict: true
|
||||
maybeValue: T | null
|
||||
declarationKind: interface
|
||||
avoidOptionals:
|
||||
field: true
|
||||
inputValue: false
|
||||
object: false
|
||||
defaultValue: false
|
||||
preResolveTypes: true
|
||||
namingConvention:
|
||||
enumValues: keep
|
||||
scalars:
|
||||
DateTime: string
|
||||
Date: string
|
||||
Decimal: number
|
||||
UUID: string
|
||||
ID: string
|
||||
JSON: Record<string, string>
|
||||
Upload: File
|
||||
SafeInt: number
|
||||
overwrite: true
|
||||
schema: ../../backend/server/src/schema.gql
|
||||
documents: ./src/**/*.gql
|
||||
generates:
|
||||
./src/schema.ts:
|
||||
plugins:
|
||||
- typescript
|
||||
- typescript-operations
|
||||
- ./export-gql-plugin.cjs:
|
||||
output: ./src/graphql/index.ts
|
||||
302
packages/common/graphql/export-gql-plugin.cjs
Normal file
302
packages/common/graphql/export-gql-plugin.cjs
Normal file
@@ -0,0 +1,302 @@
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const { Kind, print, visit, TypeInfo, visitWithTypeInfo } = require('graphql');
|
||||
const { upperFirst, lowerFirst } = require('lodash');
|
||||
|
||||
/**
|
||||
* return exported name used in runtime.
|
||||
*
|
||||
* @param {import('graphql').ExecutableDefinitionNode} def
|
||||
* @returns {string}
|
||||
*/
|
||||
function getExportedName(def) {
|
||||
const name = lowerFirst(def.name?.value);
|
||||
const suffix =
|
||||
def.kind === Kind.OPERATION_DEFINITION
|
||||
? upperFirst(def.operation)
|
||||
: 'Fragment';
|
||||
return name.endsWith(suffix) ? name : name + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a field is deprecated in the schema
|
||||
*
|
||||
* @param {import('graphql').GraphQLSchema} schema
|
||||
* @param {string} typeName
|
||||
* @param {string} fieldName
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function fieldDeprecation(schema, typeName, fieldName) {
|
||||
const type = schema.getType(typeName);
|
||||
if (!type || !type.getFields) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const fields = type.getFields();
|
||||
const field = fields[fieldName];
|
||||
|
||||
return field?.deprecationReason
|
||||
? {
|
||||
name: fieldName,
|
||||
reason: field.deprecationReason,
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a query uses deprecated fields
|
||||
*
|
||||
* @param {import('graphql').GraphQLSchema} schema
|
||||
* @param {import('graphql').DocumentNode} document
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function parseDeprecations(schema, document) {
|
||||
const deprecations = [];
|
||||
|
||||
const typeInfo = new TypeInfo(schema);
|
||||
|
||||
visit(
|
||||
document,
|
||||
visitWithTypeInfo(typeInfo, {
|
||||
Field: {
|
||||
enter(node) {
|
||||
const parentType = typeInfo.getParentType();
|
||||
if (parentType && node.name) {
|
||||
const fieldName = node.name.value;
|
||||
let deprecation;
|
||||
if (
|
||||
parentType.name &&
|
||||
(deprecation = fieldDeprecation(
|
||||
schema,
|
||||
parentType.name,
|
||||
fieldName
|
||||
))
|
||||
) {
|
||||
deprecations.push(deprecation);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return deprecations.map(
|
||||
({ name, reason }) => `'${name}' is deprecated: ${reason}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {import('@graphql-codegen/plugin-helpers').CodegenPlugin}
|
||||
*/
|
||||
module.exports = {
|
||||
plugin: (schema, documents, { output }) => {
|
||||
const defs = new Map();
|
||||
const queries = [];
|
||||
const mutations = [];
|
||||
|
||||
const nameLocationMap = new Map();
|
||||
const locationSourceMap = new Map(
|
||||
documents
|
||||
.filter(source => !!source.location)
|
||||
.map(source => [source.location, source])
|
||||
);
|
||||
|
||||
function addDef(exportedName, location) {
|
||||
if (nameLocationMap.has(exportedName)) {
|
||||
throw new Error(
|
||||
`name ${exportedName} export from ${location} are duplicated.`
|
||||
);
|
||||
}
|
||||
|
||||
nameLocationMap.set(exportedName, location);
|
||||
}
|
||||
|
||||
function parseImports(location) {
|
||||
if (!location) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// parse '#import' lines
|
||||
const importedDefinitions = [];
|
||||
fs.readFileSync(location, 'utf-8')
|
||||
.split(/\r\n|\r|\n/)
|
||||
.forEach(line => {
|
||||
if (line[0] === '#') {
|
||||
const [importKeyword, importPath] = line.split(' ').filter(Boolean);
|
||||
if (importKeyword === '#import') {
|
||||
const realImportPath = path.posix.join(
|
||||
location,
|
||||
'..',
|
||||
importPath.replace(/["']/g, '')
|
||||
);
|
||||
const imports =
|
||||
locationSourceMap.get(realImportPath)?.document.definitions;
|
||||
if (imports) {
|
||||
importedDefinitions.push(...imports);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return importedDefinitions
|
||||
.map(def => `\${${getExportedName(def)}}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
for (const [location, source] of locationSourceMap) {
|
||||
if (!source || !source.document || !source.rawSDL) {
|
||||
return;
|
||||
}
|
||||
|
||||
visit(source.document, {
|
||||
[Kind.OPERATION_DEFINITION]: {
|
||||
enter: node => {
|
||||
if (!node.name) {
|
||||
throw new Error(
|
||||
`Anonymous operation definition found in ${location}.`
|
||||
);
|
||||
}
|
||||
|
||||
const exportedName = getExportedName(node);
|
||||
addDef(exportedName, location);
|
||||
|
||||
// parse 'file' fields
|
||||
const containsFile = node.variableDefinitions.some(def => {
|
||||
const varType = def?.type?.type?.name?.value;
|
||||
const checkContainFile = type => {
|
||||
if (schema.getType(type)?.name === 'Upload') return true;
|
||||
const typeDef = schema.getType(type);
|
||||
const fields = typeDef.getFields?.();
|
||||
if (!fields || typeof fields !== 'object') return false;
|
||||
for (let field of Object.values(fields)) {
|
||||
let type = field.type;
|
||||
while (type.ofType) {
|
||||
type = type.ofType;
|
||||
}
|
||||
if (type.name === 'Upload') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return varType ? checkContainFile(varType) : false;
|
||||
});
|
||||
|
||||
// Check if the query uses deprecated fields
|
||||
const deprecations = parseDeprecations(schema, source.document);
|
||||
|
||||
const imports = parseImports(location);
|
||||
|
||||
defs.set(exportedName, {
|
||||
type: node.operation,
|
||||
name: exportedName,
|
||||
operationName: node.name.value,
|
||||
containsFile,
|
||||
deprecations,
|
||||
query: `${print(node)}${imports ? `\n${imports}` : ''}`,
|
||||
});
|
||||
|
||||
if (node.operation === 'query') {
|
||||
queries.push(exportedName);
|
||||
} else if (node.operation === 'mutation') {
|
||||
mutations.push(exportedName);
|
||||
}
|
||||
},
|
||||
},
|
||||
[Kind.FRAGMENT_DEFINITION]: {
|
||||
enter: node => {
|
||||
const exportedName = getExportedName(node);
|
||||
addDef(exportedName, location);
|
||||
|
||||
const imports = parseImports(location);
|
||||
|
||||
defs.set(exportedName, {
|
||||
type: 'fragment',
|
||||
name: exportedName,
|
||||
content: `${print(node)}${imports || ''}`,
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const preludes = [
|
||||
'/* do not manipulate this file manually. */',
|
||||
`export interface GraphQLQuery {
|
||||
id: string;
|
||||
op: string;
|
||||
query: string;
|
||||
file?: boolean;
|
||||
deprecations?: string[];
|
||||
}`,
|
||||
];
|
||||
|
||||
const operations = [];
|
||||
|
||||
defs.forEach(def => {
|
||||
if (def.type === 'fragment') {
|
||||
preludes.push(`export const ${def.name} = \`${def.content}\`;`);
|
||||
} else {
|
||||
let item = `export const ${def.name} = {
|
||||
id: '${def.name}' as const,
|
||||
op: '${def.operationName}',
|
||||
query: \`${def.query}\`,
|
||||
`;
|
||||
if (def.containsFile) {
|
||||
item += ' file: true,\n';
|
||||
}
|
||||
if (def.deprecations.length) {
|
||||
item += ` deprecations: ${JSON.stringify(def.deprecations)},\n`;
|
||||
}
|
||||
item += '};\n';
|
||||
|
||||
operations.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
output,
|
||||
preludes.join('\n') + '\n' + operations.join('\n')
|
||||
);
|
||||
|
||||
const queriesUnion = queries
|
||||
.map(query => {
|
||||
const queryName = upperFirst(query);
|
||||
return `{
|
||||
name: '${query}',
|
||||
variables: ${queryName}Variables,
|
||||
response: ${queryName}
|
||||
}
|
||||
`;
|
||||
})
|
||||
.join('|');
|
||||
|
||||
const mutationsUnion = mutations
|
||||
.map(query => {
|
||||
const queryName = upperFirst(query);
|
||||
return `{
|
||||
name: '${query}',
|
||||
variables: ${queryName}Variables,
|
||||
response: ${queryName}
|
||||
}
|
||||
`;
|
||||
})
|
||||
.join('|');
|
||||
const queryTypes = queriesUnion
|
||||
? `export type Queries = ${queriesUnion}`
|
||||
: '';
|
||||
const mutationsTypes = mutationsUnion
|
||||
? `export type Mutations = ${mutationsUnion}`
|
||||
: '';
|
||||
return `
|
||||
${queryTypes}
|
||||
${mutationsTypes}
|
||||
`;
|
||||
},
|
||||
validate: (_schema, _documents, { output }) => {
|
||||
if (!output) {
|
||||
throw new Error('Export plugin must be used with a output file given');
|
||||
}
|
||||
},
|
||||
};
|
||||
34
packages/common/graphql/package.json
Normal file
34
packages/common/graphql/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@affine/graphql",
|
||||
"version": "0.20.0",
|
||||
"description": "Autogenerated GraphQL client for affine.pro",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"sideEffects": "false",
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/add": "^5.0.3",
|
||||
"@graphql-codegen/cli": "5.0.5",
|
||||
"@graphql-codegen/typescript": "^4.1.2",
|
||||
"@graphql-codegen/typescript-operations": "^4.4.0",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"prettier": "^3.4.2",
|
||||
"vitest": "3.0.8"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gql-gen --errors-only"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine/debug": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/error": "workspace:*",
|
||||
"graphql": "^16.9.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash-es": "^4.17.21"
|
||||
}
|
||||
}
|
||||
107
packages/common/graphql/src/__tests__/fetcher.spec.ts
Normal file
107
packages/common/graphql/src/__tests__/fetcher.spec.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import type { Mock } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { gqlFetcherFactory } from '../fetcher';
|
||||
import type { GraphQLQuery } from '../graphql';
|
||||
|
||||
const query: GraphQLQuery = {
|
||||
id: 'query',
|
||||
query: 'query { field }',
|
||||
op: 'query',
|
||||
};
|
||||
|
||||
let fetch: Mock;
|
||||
let gql: ReturnType<typeof gqlFetcherFactory>;
|
||||
describe('GraphQL fetcher', () => {
|
||||
beforeEach(() => {
|
||||
fetch = vi.fn(() =>
|
||||
Promise.resolve(
|
||||
new Response(JSON.stringify({ data: { field: 1 } }), {
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
gql = gqlFetcherFactory('https://example.com/graphql', fetch);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fetch.mockReset();
|
||||
});
|
||||
|
||||
it('should send POST request to given endpoint', async () => {
|
||||
await gql(
|
||||
// @ts-expect-error variables is actually optional
|
||||
{ query }
|
||||
);
|
||||
|
||||
expect(fetch).toBeCalledTimes(1);
|
||||
expect(fetch.mock.lastCall?.[0]).toBe('https://example.com/graphql');
|
||||
const ctx = fetch.mock.lastCall?.[1] as RequestInit;
|
||||
expect(ctx.method).toBe('POST');
|
||||
});
|
||||
|
||||
it('should send with correct graphql JSON body', async () => {
|
||||
await gql({
|
||||
query,
|
||||
// @ts-expect-error forgive the fake variables
|
||||
variables: { a: 1, b: '2', c: { d: false } },
|
||||
});
|
||||
|
||||
expect(fetch.mock.lastCall?.[1]).toEqual(
|
||||
expect.objectContaining({
|
||||
body: '{"query":"query { field }","variables":{"a":1,"b":"2","c":{"d":false}},"operationName":"query"}',
|
||||
headers: expect.objectContaining({
|
||||
'content-type': 'application/json',
|
||||
'x-operation-name': 'query',
|
||||
}),
|
||||
method: 'POST',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should correctly ignore nil variables', async () => {
|
||||
await gql({
|
||||
query,
|
||||
// @ts-expect-error forgive the fake variables
|
||||
variables: { a: false, b: null, c: undefined },
|
||||
});
|
||||
|
||||
expect(fetch.mock.lastCall?.[1].body).toMatchInlineSnapshot(
|
||||
`"{"query":"query { field }","variables":{"a":false,"b":null},"operationName":"query"}"`
|
||||
);
|
||||
|
||||
await gql({
|
||||
query,
|
||||
// @ts-expect-error forgive the fake variables
|
||||
variables: { a: false, b: null, c: undefined },
|
||||
keepNilVariables: false,
|
||||
});
|
||||
|
||||
expect(fetch.mock.lastCall?.[1].body).toMatchInlineSnapshot(
|
||||
`"{"query":"query { field }","variables":{"a":false},"operationName":"query"}"`
|
||||
);
|
||||
});
|
||||
|
||||
it('should correct handle graphql error', async () => {
|
||||
fetch.mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: null,
|
||||
errors: [{ message: 'error', path: ['field'] }],
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
status: 400,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
await expect(
|
||||
gql({ query, variables: void 0 })
|
||||
).rejects.toMatchInlineSnapshot(`[GraphQLError: error]`);
|
||||
});
|
||||
});
|
||||
237
packages/common/graphql/src/fetcher.ts
Normal file
237
packages/common/graphql/src/fetcher.ts
Normal file
@@ -0,0 +1,237 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { GraphQLError } from '@affine/error';
|
||||
import type { ExecutionResult } from 'graphql';
|
||||
import { isNil, isObject, merge } from 'lodash-es';
|
||||
|
||||
import type { GraphQLQuery } from './graphql';
|
||||
import type { Mutations, Queries } from './schema';
|
||||
|
||||
export type NotArray<T> = T extends Array<unknown> ? never : T;
|
||||
|
||||
export type FetchInit = RequestInit & { timeout?: number };
|
||||
|
||||
export type _QueryVariables<Q extends GraphQLQuery> =
|
||||
Q['id'] extends Queries['name']
|
||||
? Extract<Queries, { name: Q['id'] }>['variables']
|
||||
: Q['id'] extends Mutations['name']
|
||||
? Extract<Mutations, { name: Q['id'] }>['variables']
|
||||
: undefined;
|
||||
|
||||
export type QueryVariables<Q extends GraphQLQuery> =
|
||||
_QueryVariables<Q> extends never | Record<string, never>
|
||||
? never
|
||||
: _QueryVariables<Q>;
|
||||
|
||||
export type QueryResponse<Q extends GraphQLQuery> = Extract<
|
||||
Queries | Mutations,
|
||||
{ name: Q['id'] }
|
||||
>['response'];
|
||||
|
||||
type NullableKeys<T> = {
|
||||
[K in keyof T]: null extends T[K] ? K : never;
|
||||
}[keyof T];
|
||||
|
||||
type NonNullableKeys<T> = {
|
||||
[K in keyof T]: null extends T[K] ? never : K;
|
||||
}[keyof T];
|
||||
|
||||
export type RecursiveMaybeFields<T> = T extends
|
||||
| number
|
||||
| boolean
|
||||
| string
|
||||
| null
|
||||
| undefined
|
||||
? T
|
||||
: {
|
||||
[K in NullableKeys<T>]?: RecursiveMaybeFields<T[K]>;
|
||||
} & {
|
||||
[K in NonNullableKeys<T>]: RecursiveMaybeFields<T[K]>;
|
||||
};
|
||||
|
||||
type AllowedRequestContext = Omit<RequestInit, 'method' | 'body'>;
|
||||
|
||||
export interface RequestBody {
|
||||
operationName?: string;
|
||||
variables: any;
|
||||
query: string;
|
||||
form?: FormData;
|
||||
}
|
||||
|
||||
type QueryVariablesOption<Q extends GraphQLQuery> =
|
||||
QueryVariables<Q> extends never
|
||||
? {
|
||||
variables?: undefined;
|
||||
}
|
||||
: { variables: RecursiveMaybeFields<QueryVariables<Q>> };
|
||||
|
||||
export type RequestOptions<Q extends GraphQLQuery> = QueryVariablesOption<Q> & {
|
||||
/**
|
||||
* parameter passed to `fetch` function
|
||||
*/
|
||||
context?: AllowedRequestContext;
|
||||
/**
|
||||
* Whether keep null or undefined value in variables.
|
||||
*
|
||||
* if `false` given, `{ a: 0, b: undefined, c: null }` will be converted to `{ a: 0 }`
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
keepNilVariables?: boolean;
|
||||
/**
|
||||
* Request timeout in milliseconds
|
||||
* @default 15000
|
||||
*/
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
export type QueryOptions<Q extends GraphQLQuery> = RequestOptions<Q> & {
|
||||
query: Q;
|
||||
};
|
||||
export type MutationOptions<M extends GraphQLQuery> = RequestOptions<M> & {
|
||||
mutation: M;
|
||||
};
|
||||
|
||||
function filterEmptyValue(vars: any) {
|
||||
const newVars: Record<string, any> = {};
|
||||
Object.entries(vars).forEach(([key, value]) => {
|
||||
if (isNil(value)) {
|
||||
return;
|
||||
}
|
||||
if (isObject(value) && !(value instanceof File)) {
|
||||
newVars[key] = filterEmptyValue(value);
|
||||
return;
|
||||
}
|
||||
newVars[key] = value;
|
||||
});
|
||||
|
||||
return newVars;
|
||||
}
|
||||
|
||||
export function transformToForm(body: RequestBody) {
|
||||
const form = new FormData();
|
||||
const gqlBody: {
|
||||
name?: string;
|
||||
query: string;
|
||||
variables: any;
|
||||
map: any;
|
||||
} = {
|
||||
query: body.query,
|
||||
variables: body.variables,
|
||||
map: {},
|
||||
};
|
||||
|
||||
if (body.operationName) {
|
||||
gqlBody.name = body.operationName;
|
||||
}
|
||||
const map: Record<string, string[]> = {};
|
||||
const files: File[] = [];
|
||||
if (body.variables) {
|
||||
let i = 0;
|
||||
const buildMap = (key: string, value: any) => {
|
||||
if (value instanceof File) {
|
||||
map['' + i] = [key];
|
||||
files[i] = value;
|
||||
i++;
|
||||
} else if (Array.isArray(value)) {
|
||||
value.forEach((v, index) => {
|
||||
buildMap(`${key}.${index}`, v);
|
||||
});
|
||||
} else if (isObject(value)) {
|
||||
Object.entries(value).forEach(([k, v]) => {
|
||||
buildMap(`${key}.${k}`, v);
|
||||
});
|
||||
}
|
||||
};
|
||||
buildMap('variables', body.variables);
|
||||
}
|
||||
|
||||
form.set('operations', JSON.stringify(gqlBody));
|
||||
form.set('map', JSON.stringify(map));
|
||||
for (const [i, file] of files.entries()) {
|
||||
form.set(`${i}`, file);
|
||||
}
|
||||
return form;
|
||||
}
|
||||
|
||||
function formatRequestBody<Q extends GraphQLQuery>({
|
||||
query,
|
||||
variables,
|
||||
keepNilVariables,
|
||||
}: QueryOptions<Q>): RequestBody | FormData {
|
||||
const body: RequestBody = {
|
||||
query: query.query,
|
||||
variables:
|
||||
(keepNilVariables ?? true) ? variables : filterEmptyValue(variables),
|
||||
};
|
||||
|
||||
if (query.op) {
|
||||
body.operationName = query.op;
|
||||
}
|
||||
|
||||
if (query.file) {
|
||||
return transformToForm(body);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export const gqlFetcherFactory = (
|
||||
endpoint: string,
|
||||
fetcher: (input: string, init?: FetchInit) => Promise<Response> = fetch
|
||||
) => {
|
||||
const logger = new DebugLogger('GraphQL');
|
||||
const gqlFetch = async <Query extends GraphQLQuery>(
|
||||
options: QueryOptions<Query>
|
||||
): Promise<QueryResponse<Query>> => {
|
||||
if (
|
||||
BUILD_CONFIG.appBuildType === 'canary' &&
|
||||
options.query.deprecations?.length
|
||||
) {
|
||||
options.query.deprecations.forEach(deprecation => {
|
||||
logger.warn(deprecation);
|
||||
});
|
||||
}
|
||||
|
||||
const body = formatRequestBody(options);
|
||||
|
||||
const isFormData = body instanceof FormData;
|
||||
const headers: Record<string, string> = {
|
||||
'x-operation-name': options.query.op,
|
||||
};
|
||||
if (!isFormData) {
|
||||
headers['content-type'] = 'application/json';
|
||||
}
|
||||
const ret = fetcher(
|
||||
endpoint,
|
||||
merge(options.context, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: isFormData ? body : JSON.stringify(body),
|
||||
timeout: options.timeout,
|
||||
})
|
||||
).then(async res => {
|
||||
if (res.headers.get('content-type')?.startsWith('application/json')) {
|
||||
const result = (await res.json()) as ExecutionResult;
|
||||
if (res.status >= 400 || result.errors) {
|
||||
if (result.errors && result.errors.length > 0) {
|
||||
// throw the first error is enough
|
||||
const firstError = result.errors[0];
|
||||
throw new GraphQLError(firstError.message, firstError);
|
||||
} else {
|
||||
throw new GraphQLError('Empty GraphQL error body');
|
||||
}
|
||||
} else if (result.data) {
|
||||
// we have to cast here because the type of result.data is a union type
|
||||
return result.data as any;
|
||||
}
|
||||
}
|
||||
|
||||
throw new GraphQLError(
|
||||
'GraphQL query responds unexpected result, query ' + options.query.op
|
||||
);
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
return gqlFetch;
|
||||
};
|
||||
6
packages/common/graphql/src/graphql/activate-license.gql
Normal file
6
packages/common/graphql/src/graphql/activate-license.gql
Normal file
@@ -0,0 +1,6 @@
|
||||
mutation activateLicense($workspaceId: String!, $license: String!) {
|
||||
activateLicense(workspaceId: $workspaceId, license: $license) {
|
||||
installedAt
|
||||
validatedAt
|
||||
}
|
||||
}
|
||||
23
packages/common/graphql/src/graphql/admin-server-config.gql
Normal file
23
packages/common/graphql/src/graphql/admin-server-config.gql
Normal file
@@ -0,0 +1,23 @@
|
||||
#import './fragments/password-limits.gql'
|
||||
#import './fragments/credentials-requirement.gql'
|
||||
|
||||
query adminServerConfig {
|
||||
serverConfig {
|
||||
version
|
||||
baseUrl
|
||||
name
|
||||
features
|
||||
type
|
||||
initialized
|
||||
credentialsRequirement {
|
||||
...CredentialsRequirements
|
||||
}
|
||||
availableUpgrade {
|
||||
changelog
|
||||
version
|
||||
publishedAt
|
||||
url
|
||||
}
|
||||
availableUserFeatures
|
||||
}
|
||||
}
|
||||
7
packages/common/graphql/src/graphql/blob-delete.gql
Normal file
7
packages/common/graphql/src/graphql/blob-delete.gql
Normal file
@@ -0,0 +1,7 @@
|
||||
mutation deleteBlob(
|
||||
$workspaceId: String!
|
||||
$key: String!
|
||||
$permanently: Boolean
|
||||
) {
|
||||
deleteBlob(workspaceId: $workspaceId, key: $key, permanently: $permanently)
|
||||
}
|
||||
10
packages/common/graphql/src/graphql/blob-list.gql
Normal file
10
packages/common/graphql/src/graphql/blob-list.gql
Normal file
@@ -0,0 +1,10 @@
|
||||
query listBlobs($workspaceId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
blobs {
|
||||
key
|
||||
size
|
||||
mime
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation releaseDeletedBlobs($workspaceId: String!) {
|
||||
releaseDeletedBlobs(workspaceId: $workspaceId)
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/blob-set.gql
Normal file
3
packages/common/graphql/src/graphql/blob-set.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
mutation setBlob($workspaceId: String!, $blob: Upload!) {
|
||||
setBlob(workspaceId: $workspaceId, blob: $blob)
|
||||
}
|
||||
11
packages/common/graphql/src/graphql/cancel-subscription.gql
Normal file
11
packages/common/graphql/src/graphql/cancel-subscription.gql
Normal file
@@ -0,0 +1,11 @@
|
||||
mutation cancelSubscription(
|
||||
$plan: SubscriptionPlan = Pro
|
||||
$workspaceId: String
|
||||
) {
|
||||
cancelSubscription(plan: $plan, workspaceId: $workspaceId) {
|
||||
id
|
||||
status
|
||||
nextBillAt
|
||||
canceledAt
|
||||
}
|
||||
}
|
||||
6
packages/common/graphql/src/graphql/change-email.gql
Normal file
6
packages/common/graphql/src/graphql/change-email.gql
Normal file
@@ -0,0 +1,6 @@
|
||||
mutation changeEmail($token: String!, $email: String!) {
|
||||
changeEmail(token: $token, email: $email) {
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createChangePasswordUrl($callbackUrl: String!, $userId: String!) {
|
||||
createChangePasswordUrl(callbackUrl: $callbackUrl, userId: $userId)
|
||||
}
|
||||
7
packages/common/graphql/src/graphql/change-password.gql
Normal file
7
packages/common/graphql/src/graphql/change-password.gql
Normal file
@@ -0,0 +1,7 @@
|
||||
mutation changePassword(
|
||||
$token: String!
|
||||
$userId: String!
|
||||
$newPassword: String!
|
||||
) {
|
||||
changePassword(token: $token, userId: $userId, newPassword: $newPassword)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
mutation addContextCategory($options: AddRemoveContextCategoryInput!) {
|
||||
addContextCategory(options: $options) {
|
||||
id
|
||||
createdAt
|
||||
type
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation removeContextCategory($options: AddRemoveContextCategoryInput!) {
|
||||
removeContextCategory(options: $options)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createCopilotContext($workspaceId: String!, $sessionId: String!) {
|
||||
createCopilotContext(workspaceId: $workspaceId, sessionId: $sessionId)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
mutation addContextDoc($options: AddContextDocInput!) {
|
||||
addContextDoc(options: $options) {
|
||||
id
|
||||
createdAt
|
||||
status
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation removeContextDoc($options: RemoveContextDocInput!) {
|
||||
removeContextDoc(options: $options)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
mutation addContextFile($content: Upload!, $options: AddContextFileInput!) {
|
||||
addContextFile(content: $content, options: $options) {
|
||||
id
|
||||
createdAt
|
||||
name
|
||||
chunkSize
|
||||
error
|
||||
status
|
||||
blobId
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
query matchContext($contextId: String!, $content: String!, $limit: SafeInt) {
|
||||
currentUser {
|
||||
copilot {
|
||||
contexts(contextId: $contextId) {
|
||||
matchContext(content: $content, limit: $limit) {
|
||||
fileId
|
||||
chunk
|
||||
content
|
||||
distance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation removeContextFile($options: RemoveContextFileInput!) {
|
||||
removeContextFile(options: $options)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
query listContextObject(
|
||||
$workspaceId: String!
|
||||
$sessionId: String!
|
||||
$contextId: String!
|
||||
) {
|
||||
currentUser {
|
||||
copilot(workspaceId: $workspaceId) {
|
||||
contexts(sessionId: $sessionId, contextId: $contextId) {
|
||||
docs {
|
||||
id
|
||||
status
|
||||
createdAt
|
||||
}
|
||||
files {
|
||||
id
|
||||
name
|
||||
blobId
|
||||
chunkSize
|
||||
error
|
||||
status
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
packages/common/graphql/src/graphql/copilot-context-list.gql
Normal file
10
packages/common/graphql/src/graphql/copilot-context-list.gql
Normal file
@@ -0,0 +1,10 @@
|
||||
query listContext($workspaceId: String!, $sessionId: String!) {
|
||||
currentUser {
|
||||
copilot(workspaceId: $workspaceId) {
|
||||
contexts(sessionId: $sessionId) {
|
||||
id
|
||||
workspaceId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
query matchWorkspaceContext($contextId: String!, $content: String!, $limit: SafeInt) {
|
||||
currentUser {
|
||||
copilot {
|
||||
contexts(contextId: $contextId) {
|
||||
matchWorkspaceContext(content: $content, limit: $limit) {
|
||||
docId
|
||||
chunk
|
||||
content
|
||||
distance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
query getWorkspaceEmbeddingStatus($workspaceId: String!) {
|
||||
queryWorkspaceEmbeddingStatus(workspaceId: $workspaceId) {
|
||||
total
|
||||
embedded
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation queueWorkspaceEmbedding($workspaceId: String!, $docId: [String!]!) {
|
||||
queueWorkspaceEmbedding(workspaceId: $workspaceId, docId: $docId)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
query getCopilotHistoryIds(
|
||||
$workspaceId: String!
|
||||
$docId: String
|
||||
$options: QueryChatHistoriesInput
|
||||
) {
|
||||
currentUser {
|
||||
copilot(workspaceId: $workspaceId) {
|
||||
histories(docId: $docId, options: $options) {
|
||||
sessionId
|
||||
messages {
|
||||
id
|
||||
role
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
packages/common/graphql/src/graphql/copilot-history-list.gql
Normal file
23
packages/common/graphql/src/graphql/copilot-history-list.gql
Normal file
@@ -0,0 +1,23 @@
|
||||
query getCopilotHistories(
|
||||
$workspaceId: String!
|
||||
$docId: String
|
||||
$options: QueryChatHistoriesInput
|
||||
) {
|
||||
currentUser {
|
||||
copilot(workspaceId: $workspaceId) {
|
||||
histories(docId: $docId, options: $options) {
|
||||
sessionId
|
||||
tokens
|
||||
action
|
||||
createdAt
|
||||
messages {
|
||||
id
|
||||
role
|
||||
content
|
||||
attachments
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createCopilotMessage($options: CreateChatMessageInput!) {
|
||||
createCopilotMessage(options: $options)
|
||||
}
|
||||
19
packages/common/graphql/src/graphql/copilot-prompt-list.gql
Normal file
19
packages/common/graphql/src/graphql/copilot-prompt-list.gql
Normal file
@@ -0,0 +1,19 @@
|
||||
query getPrompts {
|
||||
listCopilotPrompts {
|
||||
name
|
||||
model
|
||||
action
|
||||
config {
|
||||
jsonMode
|
||||
frequencyPenalty
|
||||
presencePenalty
|
||||
temperature
|
||||
topP
|
||||
}
|
||||
messages {
|
||||
role
|
||||
content
|
||||
params
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
mutation updatePrompt(
|
||||
$name: String!
|
||||
$messages: [CopilotPromptMessageInput!]!
|
||||
) {
|
||||
updateCopilotPrompt(name: $name, messages: $messages) {
|
||||
name
|
||||
model
|
||||
action
|
||||
config {
|
||||
jsonMode
|
||||
frequencyPenalty
|
||||
presencePenalty
|
||||
temperature
|
||||
topP
|
||||
}
|
||||
messages {
|
||||
role
|
||||
content
|
||||
params
|
||||
}
|
||||
}
|
||||
}
|
||||
10
packages/common/graphql/src/graphql/copilot-quota.gql
Normal file
10
packages/common/graphql/src/graphql/copilot-quota.gql
Normal file
@@ -0,0 +1,10 @@
|
||||
query copilotQuota {
|
||||
currentUser {
|
||||
copilot {
|
||||
quota {
|
||||
limit
|
||||
used
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation cleanupCopilotSession($input: DeleteSessionInput!) {
|
||||
cleanupCopilotSession(options: $input)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createCopilotSession($options: CreateChatSessionInput!) {
|
||||
createCopilotSession(options: $options)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation forkCopilotSession($options: ForkChatSessionInput!) {
|
||||
forkCopilotSession(options: $options)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation updateCopilotSession($options: UpdateChatSessionInput!) {
|
||||
updateCopilotSession(options: $options)
|
||||
}
|
||||
15
packages/common/graphql/src/graphql/copilot-sessions-get.gql
Normal file
15
packages/common/graphql/src/graphql/copilot-sessions-get.gql
Normal file
@@ -0,0 +1,15 @@
|
||||
query getCopilotSessions(
|
||||
$workspaceId: String!
|
||||
$docId: String
|
||||
$options: QueryChatSessionsInput
|
||||
) {
|
||||
currentUser {
|
||||
copilot(workspaceId: $workspaceId) {
|
||||
sessions(docId: $docId, options: $options) {
|
||||
id
|
||||
parentSessionId
|
||||
promptName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createCheckoutSession($input: CreateCheckoutSessionInput!) {
|
||||
createCheckoutSession(input: $input)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createCustomerPortal {
|
||||
createCustomerPortal
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation createSelfhostCustomerPortal ($workspaceId: String!) {
|
||||
createSelfhostWorkspaceCustomerPortal(workspaceId: $workspaceId)
|
||||
}
|
||||
5
packages/common/graphql/src/graphql/create-user.gql
Normal file
5
packages/common/graphql/src/graphql/create-user.gql
Normal file
@@ -0,0 +1,5 @@
|
||||
mutation createUser($input: CreateUserInput!) {
|
||||
createUser(input: $input) {
|
||||
id
|
||||
}
|
||||
}
|
||||
7
packages/common/graphql/src/graphql/create-workspace.gql
Normal file
7
packages/common/graphql/src/graphql/create-workspace.gql
Normal file
@@ -0,0 +1,7 @@
|
||||
mutation createWorkspace {
|
||||
createWorkspace {
|
||||
id
|
||||
public
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation deactivateLicense($workspaceId: String!) {
|
||||
deactivateLicense(workspaceId: $workspaceId)
|
||||
}
|
||||
5
packages/common/graphql/src/graphql/delete-account.gql
Normal file
5
packages/common/graphql/src/graphql/delete-account.gql
Normal file
@@ -0,0 +1,5 @@
|
||||
mutation deleteAccount {
|
||||
deleteAccount {
|
||||
success
|
||||
}
|
||||
}
|
||||
5
packages/common/graphql/src/graphql/delete-user.gql
Normal file
5
packages/common/graphql/src/graphql/delete-user.gql
Normal file
@@ -0,0 +1,5 @@
|
||||
mutation deleteUser($id: String!) {
|
||||
deleteUser(id: $id) {
|
||||
success
|
||||
}
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/delete-workspace.gql
Normal file
3
packages/common/graphql/src/graphql/delete-workspace.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
mutation deleteWorkspace($id: String!) {
|
||||
deleteWorkspace(id: $id)
|
||||
}
|
||||
6
packages/common/graphql/src/graphql/disable-user.gql
Normal file
6
packages/common/graphql/src/graphql/disable-user.gql
Normal file
@@ -0,0 +1,6 @@
|
||||
mutation disableUser($id: String!) {
|
||||
banUser(id: $id) {
|
||||
email
|
||||
disabled
|
||||
}
|
||||
}
|
||||
21
packages/common/graphql/src/graphql/doc-role-permissions.gql
Normal file
21
packages/common/graphql/src/graphql/doc-role-permissions.gql
Normal file
@@ -0,0 +1,21 @@
|
||||
query getDocRolePermissions($workspaceId: String!, $docId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
doc(docId: $docId) {
|
||||
permissions {
|
||||
Doc_Copy
|
||||
Doc_Delete
|
||||
Doc_Duplicate
|
||||
Doc_Properties_Read
|
||||
Doc_Properties_Update
|
||||
Doc_Publish
|
||||
Doc_Read
|
||||
Doc_Restore
|
||||
Doc_TransferOwner
|
||||
Doc_Trash
|
||||
Doc_Update
|
||||
Doc_Users_Manage
|
||||
Doc_Users_Read
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
6
packages/common/graphql/src/graphql/enable-user.gql
Normal file
6
packages/common/graphql/src/graphql/enable-user.gql
Normal file
@@ -0,0 +1,6 @@
|
||||
mutation enableUser($id: String!) {
|
||||
enableUser(id: $id) {
|
||||
email
|
||||
disabled
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fragment CredentialsRequirements on CredentialsRequirementType {
|
||||
password {
|
||||
...PasswordLimits
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fragment PasswordLimits on PasswordLimitsType {
|
||||
minLength
|
||||
maxLength
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation generateLicenseKey($sessionId: String!) {
|
||||
generateLicenseKey(sessionId: $sessionId)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# for the admin panel only, do not use it in the app
|
||||
query getCurrentUserFeatures {
|
||||
currentUser {
|
||||
id
|
||||
name
|
||||
email
|
||||
emailVerified
|
||||
avatarUrl
|
||||
features
|
||||
}
|
||||
}
|
||||
12
packages/common/graphql/src/graphql/get-current-user.gql
Normal file
12
packages/common/graphql/src/graphql/get-current-user.gql
Normal file
@@ -0,0 +1,12 @@
|
||||
query getCurrentUser {
|
||||
currentUser {
|
||||
id
|
||||
name
|
||||
email
|
||||
emailVerified
|
||||
avatarUrl
|
||||
token {
|
||||
sessionToken
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
query getDocDefaultRole($workspaceId: String!, $docId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
doc(docId: $docId) {
|
||||
defaultRole
|
||||
}
|
||||
}
|
||||
}
|
||||
14
packages/common/graphql/src/graphql/get-invite-info.gql
Normal file
14
packages/common/graphql/src/graphql/get-invite-info.gql
Normal file
@@ -0,0 +1,14 @@
|
||||
query getInviteInfo($inviteId: String!) {
|
||||
getInviteInfo(inviteId: $inviteId) {
|
||||
workspace {
|
||||
id
|
||||
name
|
||||
avatar
|
||||
}
|
||||
user {
|
||||
id
|
||||
name
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/get-is-admin.gql
Normal file
3
packages/common/graphql/src/graphql/get-is-admin.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
query getIsAdmin($workspaceId: String!) {
|
||||
isAdmin(workspaceId: $workspaceId)
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/get-is-owner.gql
Normal file
3
packages/common/graphql/src/graphql/get-is-owner.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
query getIsOwner($workspaceId: String!) {
|
||||
isOwner(workspaceId: $workspaceId)
|
||||
}
|
||||
11
packages/common/graphql/src/graphql/get-license.gql
Normal file
11
packages/common/graphql/src/graphql/get-license.gql
Normal file
@@ -0,0 +1,11 @@
|
||||
query getLicense($workspaceId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
license {
|
||||
expiredAt
|
||||
installedAt
|
||||
quantity
|
||||
recurring
|
||||
validatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
query getMemberCountByWorkspaceId($workspaceId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
memberCount
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
query getMembersByWorkspaceId($workspaceId: String!, $skip: Int, $take: Int, $query: String) {
|
||||
workspace(id: $workspaceId) {
|
||||
memberCount
|
||||
members(skip: $skip, take: $take, query: $query) {
|
||||
id
|
||||
name
|
||||
email
|
||||
avatarUrl
|
||||
permission
|
||||
inviteId
|
||||
emailVerified
|
||||
status
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
query oauthProviders {
|
||||
serverConfig {
|
||||
oauthProviders
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
query getPageGrantedUsersList($pagination: PaginationInput!, $docId: String!, $workspaceId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
doc(docId: $docId) {
|
||||
grantedUsersList(pagination: $pagination) {
|
||||
totalCount
|
||||
pageInfo {
|
||||
endCursor
|
||||
hasNextPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
role
|
||||
user {
|
||||
id
|
||||
name
|
||||
email
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
query getPublicUserById($id: String!) {
|
||||
publicUserById(id: $id) {
|
||||
id
|
||||
avatarUrl
|
||||
name
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
query getServerRuntimeConfig {
|
||||
serverRuntimeConfig {
|
||||
id
|
||||
module
|
||||
key
|
||||
description
|
||||
value
|
||||
type
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
query getServerServiceConfigs {
|
||||
serverServiceConfigs {
|
||||
name
|
||||
config
|
||||
}
|
||||
}
|
||||
20
packages/common/graphql/src/graphql/get-user-by-email.gql
Normal file
20
packages/common/graphql/src/graphql/get-user-by-email.gql
Normal file
@@ -0,0 +1,20 @@
|
||||
query getUserByEmail($email: String!) {
|
||||
userByEmail(email: $email) {
|
||||
id
|
||||
name
|
||||
email
|
||||
features
|
||||
hasPassword
|
||||
emailVerified
|
||||
avatarUrl
|
||||
quota {
|
||||
humanReadable {
|
||||
blobLimit
|
||||
historyPeriod
|
||||
memberLimit
|
||||
name
|
||||
storageQuota
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
query getUserFeatures {
|
||||
currentUser {
|
||||
id
|
||||
features
|
||||
}
|
||||
}
|
||||
16
packages/common/graphql/src/graphql/get-user.gql
Normal file
16
packages/common/graphql/src/graphql/get-user.gql
Normal file
@@ -0,0 +1,16 @@
|
||||
query getUser($email: String!) {
|
||||
user(email: $email) {
|
||||
__typename
|
||||
... on UserType {
|
||||
id
|
||||
name
|
||||
avatarUrl
|
||||
email
|
||||
hasPassword
|
||||
}
|
||||
... on LimitedUserType {
|
||||
email
|
||||
hasPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/get-users-count.gql
Normal file
3
packages/common/graphql/src/graphql/get-users-count.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
query getUsersCount {
|
||||
usersCount
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
query getWorkspaceInfo($workspaceId: String!) {
|
||||
isAdmin(workspaceId: $workspaceId)
|
||||
isOwner(workspaceId: $workspaceId)
|
||||
workspace(id: $workspaceId) {
|
||||
team
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
query getWorkspacePageById($workspaceId: String!, $pageId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
doc(docId: $pageId) {
|
||||
id
|
||||
mode
|
||||
defaultRole
|
||||
public
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
query getWorkspacePageMetaById($id: String!, $pageId: String!) {
|
||||
workspace(id: $id) {
|
||||
pageMeta(pageId: $pageId) {
|
||||
createdAt
|
||||
updatedAt
|
||||
createdBy {
|
||||
name
|
||||
avatarUrl
|
||||
}
|
||||
updatedBy {
|
||||
name
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
query getWorkspacePublicById($id: String!) {
|
||||
workspace(id: $id) {
|
||||
public
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
query getWorkspacePublicPages($workspaceId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
publicDocs {
|
||||
id
|
||||
mode
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
query getWorkspaceSubscription($workspaceId: String!) {
|
||||
workspace(id: $workspaceId) {
|
||||
subscription {
|
||||
id
|
||||
status
|
||||
plan
|
||||
recurring
|
||||
start
|
||||
end
|
||||
nextBillAt
|
||||
canceledAt
|
||||
variant
|
||||
}
|
||||
}
|
||||
}
|
||||
5
packages/common/graphql/src/graphql/get-workspace.gql
Normal file
5
packages/common/graphql/src/graphql/get-workspace.gql
Normal file
@@ -0,0 +1,5 @@
|
||||
query getWorkspace($id: String!) {
|
||||
workspace(id: $id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
10
packages/common/graphql/src/graphql/get-workspaces.gql
Normal file
10
packages/common/graphql/src/graphql/get-workspaces.gql
Normal file
@@ -0,0 +1,10 @@
|
||||
query getWorkspaces {
|
||||
workspaces {
|
||||
id
|
||||
initialized
|
||||
team
|
||||
owner {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation grantDocUserRoles($input: GrantDocUserRolesInput!) {
|
||||
grantDocUserRoles(input: $input)
|
||||
}
|
||||
17
packages/common/graphql/src/graphql/histories.gql
Normal file
17
packages/common/graphql/src/graphql/histories.gql
Normal file
@@ -0,0 +1,17 @@
|
||||
query listHistory(
|
||||
$workspaceId: String!
|
||||
$pageDocId: String!
|
||||
$take: Int
|
||||
$before: DateTime
|
||||
) {
|
||||
workspace(id: $workspaceId) {
|
||||
histories(guid: $pageDocId, take: $take, before: $before) {
|
||||
id
|
||||
timestamp
|
||||
editor {
|
||||
name
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
packages/common/graphql/src/graphql/import-users.gql
Normal file
14
packages/common/graphql/src/graphql/import-users.gql
Normal file
@@ -0,0 +1,14 @@
|
||||
mutation ImportUsers($input: ImportUsersInput!) {
|
||||
importUsers(input: $input) {
|
||||
__typename
|
||||
... on UserType {
|
||||
id
|
||||
name
|
||||
email
|
||||
}
|
||||
... on UserImportFailedType {
|
||||
email
|
||||
error
|
||||
}
|
||||
}
|
||||
}
|
||||
1663
packages/common/graphql/src/graphql/index.ts
Normal file
1663
packages/common/graphql/src/graphql/index.ts
Normal file
File diff suppressed because it is too large
Load Diff
5
packages/common/graphql/src/graphql/invoices-count.gql
Normal file
5
packages/common/graphql/src/graphql/invoices-count.gql
Normal file
@@ -0,0 +1,5 @@
|
||||
query getInvoicesCount {
|
||||
currentUser {
|
||||
invoiceCount
|
||||
}
|
||||
}
|
||||
15
packages/common/graphql/src/graphql/invoices.gql
Normal file
15
packages/common/graphql/src/graphql/invoices.gql
Normal file
@@ -0,0 +1,15 @@
|
||||
query invoices($take: Int!, $skip: Int!) {
|
||||
currentUser {
|
||||
invoiceCount
|
||||
invoices(take: $take, skip: $skip) {
|
||||
id
|
||||
status
|
||||
currency
|
||||
amount
|
||||
reason
|
||||
lastPaymentError
|
||||
link
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/leave-workspace.gql
Normal file
3
packages/common/graphql/src/graphql/leave-workspace.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
mutation leaveWorkspace($workspaceId: String!, $sendLeaveMail: Boolean) {
|
||||
leaveWorkspace(workspaceId: $workspaceId, sendLeaveMail: $sendLeaveMail)
|
||||
}
|
||||
25
packages/common/graphql/src/graphql/list-notifications.gql
Normal file
25
packages/common/graphql/src/graphql/list-notifications.gql
Normal file
@@ -0,0 +1,25 @@
|
||||
query listNotifications($pagination: PaginationInput!) {
|
||||
currentUser {
|
||||
notifications(pagination: $pagination) {
|
||||
totalCount
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
id
|
||||
type
|
||||
level
|
||||
read
|
||||
createdAt
|
||||
updatedAt
|
||||
body
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
packages/common/graphql/src/graphql/list-users.gql
Normal file
12
packages/common/graphql/src/graphql/list-users.gql
Normal file
@@ -0,0 +1,12 @@
|
||||
query listUsers($filter: ListUserInput!) {
|
||||
users(filter: $filter) {
|
||||
id
|
||||
name
|
||||
email
|
||||
disabled
|
||||
features
|
||||
hasPassword
|
||||
emailVerified
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
3
packages/common/graphql/src/graphql/mention-user.gql
Normal file
3
packages/common/graphql/src/graphql/mention-user.gql
Normal file
@@ -0,0 +1,3 @@
|
||||
mutation mentionUser($input: MentionInput!) {
|
||||
mentionUser(input: $input)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
query notificationCount {
|
||||
currentUser {
|
||||
notificationCount
|
||||
}
|
||||
}
|
||||
10
packages/common/graphql/src/graphql/prices.gql
Normal file
10
packages/common/graphql/src/graphql/prices.gql
Normal file
@@ -0,0 +1,10 @@
|
||||
query prices {
|
||||
prices {
|
||||
type
|
||||
plan
|
||||
currency
|
||||
amount
|
||||
yearlyAmount
|
||||
lifetimeAmount
|
||||
}
|
||||
}
|
||||
10
packages/common/graphql/src/graphql/public-page.gql
Normal file
10
packages/common/graphql/src/graphql/public-page.gql
Normal file
@@ -0,0 +1,10 @@
|
||||
mutation publishPage(
|
||||
$workspaceId: String!
|
||||
$pageId: String!
|
||||
$mode: PublicDocMode = Page
|
||||
) {
|
||||
publishDoc(workspaceId: $workspaceId, docId: $pageId, mode: $mode) {
|
||||
id
|
||||
mode
|
||||
}
|
||||
}
|
||||
22
packages/common/graphql/src/graphql/quota.gql
Normal file
22
packages/common/graphql/src/graphql/quota.gql
Normal file
@@ -0,0 +1,22 @@
|
||||
query quota {
|
||||
currentUser {
|
||||
id
|
||||
quota {
|
||||
name
|
||||
blobLimit
|
||||
storageQuota
|
||||
historyPeriod
|
||||
memberLimit
|
||||
humanReadable {
|
||||
name
|
||||
blobLimit
|
||||
storageQuota
|
||||
historyPeriod
|
||||
memberLimit
|
||||
}
|
||||
}
|
||||
quotaUsage {
|
||||
storageQuota
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation readNotification($id: String!) {
|
||||
readNotification(id: $id)
|
||||
}
|
||||
7
packages/common/graphql/src/graphql/recover-doc.gql
Normal file
7
packages/common/graphql/src/graphql/recover-doc.gql
Normal file
@@ -0,0 +1,7 @@
|
||||
mutation recoverDoc(
|
||||
$workspaceId: String!
|
||||
$docId: String!
|
||||
$timestamp: DateTime!
|
||||
) {
|
||||
recoverDoc(workspaceId: $workspaceId, guid: $docId, timestamp: $timestamp)
|
||||
}
|
||||
5
packages/common/graphql/src/graphql/remove-avatar.gql
Normal file
5
packages/common/graphql/src/graphql/remove-avatar.gql
Normal file
@@ -0,0 +1,5 @@
|
||||
mutation removeAvatar {
|
||||
removeAvatar {
|
||||
success
|
||||
}
|
||||
}
|
||||
12
packages/common/graphql/src/graphql/resume-subscription.gql
Normal file
12
packages/common/graphql/src/graphql/resume-subscription.gql
Normal file
@@ -0,0 +1,12 @@
|
||||
mutation resumeSubscription(
|
||||
$plan: SubscriptionPlan = Pro
|
||||
$workspaceId: String
|
||||
) {
|
||||
resumeSubscription(plan: $plan, workspaceId: $workspaceId) {
|
||||
id
|
||||
status
|
||||
nextBillAt
|
||||
start
|
||||
end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation revokeDocUserRoles($input: RevokeDocUserRoleInput!) {
|
||||
revokeDocUserRoles(input: $input)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user