Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
/*
GraphQL Plugin default options for base schema and resolvers
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const apollo_server_caching_1 = require("apollo-server-caching");
const graphql_upload_1 = require("graphql-upload");
const graphql_type_json_1 = require("graphql-type-json");
const graphql_iso_date_1 = require("graphql-iso-date");
// TODO: as preset
delete graphql_upload_1.GraphQLUpload.description;
delete graphql_type_json_1.GraphQLJSON.description;
delete graphql_iso_date_1.GraphQLDate.description;
delete graphql_iso_date_1.GraphQLDateTime.description;
delete graphql_iso_date_1.GraphQLTime.description;
const typeDefs = [];
const resolvers = {};
/* default scalar types */
typeDefs.push(`
"""
Upload scalar type
@input: [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec)
@output: { filename, mimetype, encoding, createReadStream }
filename string File name.
mimetype string File MIME type. Provided by the client and can’t be trusted.
encoding string File stream transfer encoding.
createReadStream Function Returns a Node.js readable stream of the file contents, for processing and storing the file. Multiple calls create independent streams. Throws if called after all resolvers have resolved, or after an error has interrupted the request.
"""
/*
GraphQL Plugin default options for base schema and resolvers
*/
import { GraphQLHandlersOptions } from "./handlers";
import { InMemoryLRUCache } from "apollo-server-caching";
import { GraphQLUpload } from "graphql-upload";
import { GraphQLJSON } from "graphql-type-json";
import { GraphQLDate, GraphQLDateTime, GraphQLTime } from "graphql-iso-date";
// TODO: as preset
delete GraphQLUpload.description;
delete GraphQLJSON.description;
delete GraphQLDate.description;
delete GraphQLDateTime.description;
delete GraphQLTime.description;
const typeDefs: string[] = [];
const resolvers: any = {};
/* default scalar types */
typeDefs.push(`
"""
Upload scalar type
@input: [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec)
@output: { filename, mimetype, encoding, createReadStream }
filename string File name.
mimetype string File MIME type. Provided by the client and can’t be trusted.
encoding string File stream transfer encoding.
for (const arg of directive.arguments) {
args[arg.name.value] =
arg.value.kind === 'StringValue'
? format(
arg.value.value,
Object.assign(
{},
{
parent: source,
args: fieldArgs,
context
}
),
{partial: true}
)
: arg.value.value || GraphQLJSON.parseLiteral(arg.value);
}
args = Object.assign({}, args, fieldArgs);
return (
directiveConfig &&
directiveConfig.resolve &&
directiveConfig.resolve(resolve, source, args, context, info)
);
}
parseLiteral(value) {
return GraphQLJSON.parseLiteral(value);
},
});
mimetype string File MIME type. Provided by the client and can’t be trusted.
encoding string File stream transfer encoding.
createReadStream Function Returns a Node.js readable stream of the file contents, for processing and storing the file. Multiple calls create independent streams. Throws if called after all resolvers have resolved, or after an error has interrupted the request.
"""
scalar Upload
`);
resolvers.Upload = graphql_upload_1.GraphQLUpload;
typeDefs.push(`
"""
JSON scalar type
@input: JSON string
@output: Result of JSON.parse(@input)
"""
scalar JSON
`);
resolvers.JSON = graphql_type_json_1.GraphQLJSON;
typeDefs.push(`
"""
Date scalar type
@input: RFC3339 full-date string: "2007-12-03"
@output: Date instance
"""
scalar Date
`);
resolvers.Date = graphql_iso_date_1.GraphQLDate;
typeDefs.push(`
"""
Time scalar type
@input: RFC3339 full-time string (UTC): "13:10:20Z"
@output: Date instance
"""
scalar Time
name: 'AWSDateTime',
description: GraphQLDateTime.description,
serialize(value) {
return GraphQLDateTime.serialize(value);
},
parseValue(value) {
return GraphQLDateTime.parseValue(value) ? value : undefined;
},
parseLiteral(value) {
return GraphQLDateTime.parseLiteral(value) ? value.value : undefined;
},
});
const AWSJSON = new GraphQLScalarType({
name: 'AWSJSON',
description: GraphQLJSON.description,
serialize(value) {
return JSON.stringify(GraphQLJSON.serialize(value));
},
parseValue(value) {
return GraphQLJSON.parseValue(value);
},
parseLiteral(value) {
return GraphQLJSON.parseLiteral(value);
},
});
const scalars = {
AWSJSON,
AWSDate,
AWSTime,
AWSDateTime,
parseValue(value) {
return GraphQLJSON.parseValue(value);
},
parseLiteral(value) {
serialize(value) {
return JSON.stringify(GraphQLJSON.serialize(value));
},
parseValue(value) {