Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export: 'const',
name: `with${convertedName}`,
};
}
if (component) {
selectionSetTypes[prefix + 'Component'] = {
export: 'const',
name: this.convertName(baseName, { suffix: 'Component' }),
};
}
if (hooks) {
selectionSetTypes['use' + prefix] = {
export: 'const',
name: 'use' + this.convertName(baseName, { suffix: toPascalCase(node.operation) }),
};
}
}
const operationsBlock = this.printTypes(selectionSetTypes);
if (!this.config.noNamespaces) {
results.push(
new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind('namespace')
.withName(convertedName)
.withBlock(operationsBlock).string
);
} else {
results.push(operationsBlock);
protected buildOperationBlock(node: OperationDefinitionNode): SelectionSetToObjectResult {
const typeName = this.getRootType(node.operation);
const baseName = this.convertName(node.name.value, { suffix: `${toPascalCase(node.operation)}` });
const typesPrefix = this.config.noNamespaces ? this.convertName(node.name.value) : '';
const selectionSetTypes: SelectionSetToObjectResult = {
[typesPrefix + this.convertName('Variables')]: {
export: 'type',
name: this.convertName(node.name.value, { suffix: `${toPascalCase(node.operation)}Variables` }),
},
};
selectionSetToTypes(typesPrefix, this, this._schema, typeName, baseName, node.operation, node.selectionSet, this.config.preResolveTypes, selectionSetTypes);
return selectionSetTypes;
}
export function makePascalCase(typename: string) {
return toPascalCase(typename);
}
export function makeShortName(typename: string, trimString: string = undefined) {
return `${toPascalCase(trimString ? typename.replace(trimString, "") : typename)}`;
}
OperationDefinition(node: OperationDefinitionNode): string {
this.visitingFragment = false;
const operationType = toPascalCase(node.operation);
const operationSchemaType = this.getRootType(node.operation);
const className = node.name.value.endsWith(operationType) ? operationType : `${node.name.value}${operationType}`;
this._imports.add(Imports[operationType]);
this._imports.add(Imports.String);
this._imports.add(Imports.Override);
this._imports.add(Imports.Generated);
this._imports.add(Imports.OperationName);
this._imports.add(Imports.Operation);
this._imports.add(Imports.ResponseFieldMapper);
const cls = new JavaDeclarationBlock()
.annotate([`Generated("Apollo GraphQL")`])
.access('public')
.final()
.asKind('class')
.withName(className);
export function getIdTypeScriptFieldType(field: FieldDefinitionNode): { typeName: string; isNative: boolean } {
const postGresIdFieldType = getIdPostGresFieldType(field);
if (postGresIdFieldType.endsWith("_enum")) {
return { typeName: toPascalCase(postGresIdFieldType), isNative: false };
} else if (postGresIdFieldType.toLowerCase() === "int") {
return { typeName: "number", isNative: true };
} else {
return { typeName: "string", isNative: true };
}
}
protected buildOperationBlock(node: OperationDefinitionNode): SelectionSetToObjectResult {
const typeName = this.getRootType(node.operation);
const baseName = this.convertName(node.name.value, { suffix: `${toPascalCase(node.operation)}` });
const typesPrefix = this.config.noNamespaces ? this.convertName(node.name.value) : '';
const selectionSetTypes: SelectionSetToObjectResult = {
[typesPrefix + this.convertName('Variables')]: {
export: 'type',
name: this.convertName(node.name.value, { suffix: `${toPascalCase(node.operation)}Variables` }),
},
};
selectionSetToTypes(typesPrefix, this, this._schema, typeName, baseName, node.operation, node.selectionSet, this.config.preResolveTypes, selectionSetTypes);
return selectionSetTypes;
}