Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (subtype === 'end') {
// eslint-disable-next-line no-param-reassign
intervalMap[supertype] = tstamp - intervalMap[supertype];
}
}
let executableSchema;
if (mocks) {
// TODO: mocks doesn't yet work with a normal GraphQL schema, but it should!
// have to rewrite these functions
const myMocks = mocks || {};
if (schema instanceof GraphQLSchema) {
executableSchema = schema
} else {
executableSchema = buildSchemaFromTypeDefinitions(schema);
}
addResolveFunctionsToSchema(executableSchema, resolvers || {});
addMockFunctionsToSchema({
schema: executableSchema,
mocks: myMocks,
preserveResolvers: true,
});
} else {
// this is just basics, makeExecutableSchema should catch the rest
// TODO: should be able to provide a GraphQLschema and still use resolvers
// and connectors if you want, but at the moment this is not possible.
if (schema instanceof GraphQLSchema) {
if (logger) {
addErrorLoggingToSchema(schema, logger);
}
if (printErrors) {
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { buildSchemaFromTypeDefinitions } from 'graphql-tools';
import { schemas as serverSchemas } from '../server/graphql';
export const schemas = [...serverSchemas];
// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { buildSchemaFromTypeDefinitions } from 'graphql-tools';
import { typeDefs } from '../server/graphql';
export const schemas = [...typeDefs];
// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { buildSchemaFromTypeDefinitions } from 'graphql-tools';
import { schemas as serverSchemas } from '../server/graphql';
export const schemas = [...serverSchemas];
// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);
export function protectResolversWithAuthRules(typeDef, existingResolvers, simulator: AmplifyAppSyncSimulator) {
const schema = buildSchemaFromTypeDefinitions(typeDef);
const newResolverMap = {};
forEachField(schema, (field, typeName, fieldName) => {
const fieldResolver = getResolver(existingResolvers, typeName, fieldName);
const allowedAuthTypes = getAuthDirectiveForField(schema, field, typeName, simulator);
const allowedCognitoGroups = getAllowedCognitoGroups(schema, field, typeName);
const newResolver = (root, args, ctx: AmplifyAppSyncSimulatorRequestContext, info: GraphQLResolveInfo) => {
const currentAuthMode = ctx.requestAuthorizationMode;
if (!allowedAuthTypes.includes(currentAuthMode)) {
const err = new Unauthorized(`Not Authorized to access ${fieldName} on type ${typeName}`, info);
throw err;
}
if (
ctx.requestAuthorizationMode === AmplifyAppSyncSimulatorAuthenticationType.AMAZON_COGNITO_USER_POOLS &&
allowedCognitoGroups.length
) {
export function mockServer(
schemaDefinition: string,
mocks: MockMap = {},
automocks = defaultAutomocks
) {
const schema: GraphQLSchema = buildSchemaFromTypeDefinitions(
schemaDefinition
);
if (automocks) {
addAutomocks(schema, mocks, automocks);
}
validateMocks(mocks, schema);
forEachField(schema, (type, field) => {
field.resolve = getFieldResolver(type, field, mocks);
});
forEachInterface(schema, interfaceType => {
interfaceType.resolveType = interfaceResolveType;
});