Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// The date parameter is a Javascript Date object
return date
}
}
}
})
})
graphql(schema, `{ input(date: "2016-02-01") }`)
.then(result => {
console.log(`Example query { input(date: "2016-02-01") }: Input a valid date and output the same date`)
console.log(result)
})
.catch(console.error)
graphql(schema, `{ input(date: "2015-02-29") }`)
.then(result => {
console.log(`Example query { input(date: "2015-02-29") }: Output an error when an invalid date is passed as input (29 Feb 2015 doesn't exist)`)
console.log(result)
})
.catch(console.error)
it("does not return any suggestions", () => {
return graphql(schema, query("SUGGESTED")).then(response => {
expect(response.data.home_page.artist_module.results).toBe(null)
expect(response.errors.length).toBeGreaterThan(0)
})
})
})
it("should create instance of input object", async () => {
const mutation = `mutation {
mutationWithInput(input: { factor: 10 })
}`;
const mutationResult = await graphql(schema, mutation);
const result = mutationResult.data!.mutationWithInput;
expect(result).toBeGreaterThanOrEqual(0);
expect(result).toBeLessThanOrEqual(10);
});
it('should resolve value normally, even when resolved to a promise', async () => {
const { schema, sources: { delayedDependee } } = setup()
const result = await graphql(schema, '{ type { delayedDependee } }', null, {})
expect(result).to.have.deep.property('data.type.delayedDependee', 'delayedDependee value')
expect(delayedDependee).to.have.been.called.once
})
const execQuery = (query: string, context?: EthqlContext, variables?: { [key: string]: any }) => {
return graphql(schema, query, {}, context || prepareContext(), variables);
};
it("should find a person correctly", () => {
let testQuery = `{
getPerson(id: "3"){
name
id
}
}`;
return graphql(Schema, testQuery, undefined, {persons, findPerson, addPerson}).then((res) => {
assertNoError(res);
expect(res.data).toMatchSnapshot();
});
});
}
if (typeDefs.length === 0) {
throw new Error(`No type definitions were found matching: ${options.graphqlFileGlob}`);
}
output.push(`export const typeDefs = ${JSON.stringify(typeDefs)};`);
const schema = makeExecutableSchema({ typeDefs });
const [introspectionResult, template] = await Promise.all(
[
graphql(schema, introspectionQuery),
getTemplateGenerator('typescript'),
]
);
const introspection = introspectionResult.data;
const transformOptions = {
introspection,
documents: [],
template: template,
outPath: './',
isDev: false,
noSchema: false,
noDocuments: true,
} as TransformedOptions;
async graphql(g: any) {
let response = await graphql.graphql(this.graphQuerySchema, g.query || g, null, this.context, g.variables);
if (this.metadata.metadata.responseType === "graphql")
return new HttpResponse(response);
if (response.errors && response.errors.length > 0) {
throw new ApplicationError(response.errors[0].message);
}
return response.data;
}
}
async processRequest(request) {
const query = request.payload.query;
const variables = request.payload.variables || {};
const credentials = request.auth.credentials;
const db = await request.getDB();
const {
schema,
context,
} = await this.getOptions({ db, credentials });
const start = process.hrtime();
const result = await graphql(
schema,
query,
null,
context,
variables
);
const elapsed = process.hrtime(start);
let rootName = 'unknown';
let hasErrors = false;
if (result.data) {
rootName = Object.keys(result.data).sort().join(',');
if (rootName === 'viewer') {
rootName = Object.keys(result.data.viewer).sort().join(',');
}
processGraphQL(name, context) {
let {schema, resolvers} = this.graphql.getSchema(name);
let {query, variables} = context.params.body;
let actions = {};
for (let {id, action} of resolvers)
actions[id] = params =>
this.sandbox(action, Object.assign({}, context, {params}));
return graphql(schema, query, actions, variables);
}