Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: RawClientSideBasePluginConfig) {
super(schema, fragments, rawConfig, {});
autoBind(this);
this._additionalImports.push(`import { GraphQLClient } from 'graphql-request';`);
if (this.config.documentMode !== DocumentMode.string) {
this._additionalImports.push(`import { print } from 'graphql';`);
}
}
.map(o => {
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every(v => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue);
const doc = this.config.documentMode === DocumentMode.string ? o.documentVariableName : `print(${o.documentVariableName})`;
return `${o.node.name.value}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}): Promise<${o.operationResultType}> {
return client.request<${o.operationResultType}>(${doc}, variables);
}`;
})
.map(s => indentMultiline(s, 2));