Skip to content

Commit 4098ab9

Browse files
committed
Fixed errors with recent graphql-cli version 2.x
1 parent e0b3883 commit 4098ab9

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-cli-load",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "GraphQL CLI Data Loading plugin",
55
"files": [
66
"LICENSE",

src/load.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export const builder = {
3636
}
3737
};
3838

39-
function getSchema(config, basePath) {
40-
const schemaPath = path.join(basePath, config.schemaPath);
39+
function getSchema(config) {
40+
const schemaPath = config.schemaPath;
4141
const schemaContents = fs.readFileSync(schemaPath).toString();
4242
return buildASTSchema(parse(schemaContents));
4343
};
@@ -84,15 +84,15 @@ function getEndpoint(config, argv) {
8484
if (typeof(endpoint) === "string") {
8585
endpoint = { url: endpoint};
8686
}
87-
console.log(chalk.green(`Using endpoint ${key}: ${JSON.stringify(endpoint)}`));
87+
console.log(chalk.green(`Using endpoint ${key}: ${JSON.stringify(endpoint) }`));
8888
return endpoint;
8989
}
9090

91-
function getMutation(config, basePath, argv) {
91+
function getMutation(config, argv) {
9292
const extensions = config.extensions || {};
9393
const options = extensions.load || {};
9494

95-
const schema = getSchema(config, basePath);
95+
const schema = getSchema(config);
9696

9797
const mutationType = schema.getMutationType()
9898
if (!mutationType) {
@@ -169,22 +169,24 @@ function parseJson(str) {
169169
}
170170
}
171171

172-
export const handler = async ({getConfig},argv) => {
173-
const {config, configPath} = getConfig();
174-
const basePath = path.dirname(configPath);
172+
exports.handler = async function (context, argv) {
173+
const config = await context.getProjectConfig()
174+
const schema = config.getSchemaSDL();
175+
const configPath = config.configPath
176+
175177
const extensions = config.extensions || {};
176178
const options = extensions.load || {};
177179

178180
const endpoint = getEndpoint(config,argv);
179181
if (!endpoint) return;
180182

181-
const mutationField = getMutation(config,basePath, argv);
183+
const mutationField = getMutation(config, argv);
182184
if (!mutationField) return;
183185

184186
var args = {};
185187
mutationField.args.forEach((arg) => args[arg.name]=arg);
186188

187-
const data = readFile(basePath, options, argv);
189+
const data = readFile(path.dirname(configPath), options, argv);
188190
const mapping = parseJson(argv.mapping||"null") || options.mapping || {};
189191
if (Object.keys(mapping).length > 0) {
190192
console.log(chalk.yellow(`Using mapping: ${JSON.stringify(mapping)}`));

0 commit comments

Comments
 (0)