Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('description changed', () => {
const a = buildSchema(/* GraphQL */ `
type Query {
fieldA: String
}
"""
Old Description
"""
enum enumA {
A
B
}
`);
const b = buildSchema(/* GraphQL */ `
type Query {
fieldA: String
}
"""
New Description
"""
enum enumA {
A
B
}
`);
const changes = diff(a, b);
const change = findFirstChangeByPath(changes, 'enumA');
test('added', async () => {
const a = buildSchema(/* GraphQL */ `
interface Foo {
a: String!
b: String!
}
`);
const b = buildSchema(/* GraphQL */ `
interface Foo {
a: String!
b: String!
c: String!
}
`);
const change = findFirstChangeByPath(await diff(a, b), 'Foo.c');
expect(change.criticality.level).toEqual(CriticalityLevel.NonBreaking);
if (isString(schema)) {
// is is a path to schema folder?
try {
const schemaPath = path.resolve(schema);
const exists = fs.existsSync(schemaPath);
if (exists) {
introspectResult = await introspectSchemaViaLocalFile(schemaPath);
}
} catch {
// fall-through in case the provided string is a graphql definition,
// which can make path.resolve throw error
}
// it's not a folder, maybe it's a schema definition
if (!introspectResult) {
const schemaViaStr = buildSchema(schema);
introspectResult = await introspectSchema(schemaViaStr);
}
} else {
introspectResult = await introspectSchema(schema);
}
const tsGenerator = new TypeScriptGenerator(mergedOptions, introspectResult);
const typeDefs = await tsGenerator.generate();
let typeResolvers: GenerateResolversResult = {
body: [],
importHeader: []
};
const tsResolverGenerator = new TSResolverGenerator(mergedOptions, introspectResult);
typeResolvers = await tsResolverGenerator.generate();
function getContractSchema(expectedSchemaFile: string): GraphQLSchema {
const data = fs.readFileSync(expectedSchemaFile, "utf8")
return buildSchema(data)
}
function Module (options = {}) {
const schema = buildSchema(options.schema);
return ({controller, path}) => {
return {
state: {},
signals: {
test: [
function query ({graphql, props}) {
return graphql.query(props.query)
},
function setResponse ({props, state}) {
state.set(`graphql.data`, props.data)
}
]
},
provider (context) {
const resolvers = Object.assign({}, options.root);
function readLocalSchema(schemaPath: string): GraphQLSchema {
let schemaString: string;
if (isGlob(schemaPath)) {
const typesArray = fileLoader(schemaPath);
if (typesArray.length === 0) {
throw new Error(`No types found with glob pattern '${schemaPath}'`);
}
schemaString = mergeTypes(typesArray, { all: true });
} else {
schemaString = fs.readFileSync(schemaPath, 'utf8');
}
const schema = buildSchema(schemaString);
const introspection = introspectionFromSchema(schema, {
descriptions: false
});
return buildClientSchema(introspection);
}
import { buildSchema } from 'graphql';
import * as Koa from 'koa';
import * as mount from 'koa-mount';
import * as convert from 'koa-convert';
import * as graphqlHTTP from 'koa-graphql';
import './connect';
import { User, Post, Album } from './models';
import { UserModel, PostModel, AlbumModel } from './interfaces';
const HTTP_PORT = 3000;
const app = new Koa();
const mySchema = buildSchema(`
type Geo {
lat: String
lng: String
}
type Address {
street: String
suite: String
city: String
zipcode: String
geo: Geo
}
type Company {
name: String
catchPhrase: String
const express = require("express");
const expressGraphQL = require("express-graphql");
const { buildSchema } = require("graphql");
const schema = buildSchema(`
type Query {
hello: String
}
`);
const rootValue = {
hello: () => {
return "hello vrs";
}
};
const app = express();
app.use(
"*",
expressGraphQL({
await check.complete({
url,
context,
conclusion: CheckConclusion.Failure,
});
return;
}
const oldPointer: SchemaPointer = config.schema;
const newPointer: SchemaPointer = {
path: oldPointer.path,
ref,
};
const schemas = {
old: buildSchema(await loadFile(oldPointer)),
new: buildSchema(await loadFile(newPointer)),
};
context.log.info(`Both schemas built - ${id}`);
const actions: Array> = [];
if (config.diff) {
actions.push(
diff({
path: config.schema.path,
schemas,
}),
);
}