snapshot of https://github.com/toeverything/AFFiNE.git (canary, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 00:31:07 +05:00
commit 50f788e799
7907 changed files with 988785 additions and 0 deletions

View File

@@ -0,0 +1,305 @@
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.kind === 'NamedType'
? def.type.name.value
: 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');
}
},
};