UNPKG

mongoose-schema-to-graphql-object

Version:

Auto types generator for graphQL schema, based on your existed Mongoose schema. Check GitHub for description.

38 lines (31 loc) 1 kB
import mongoose from 'mongoose'; import { GraphQLList, GraphQLObjectType, GraphQLString } from 'graphql'; import mongooseSchemaToGraphQL from '../lib/index.min'; import { getRidOfThunks } from '../tools/util'; test('generates schemas with arrays which contain the same schema correctly', () => { const NAME = 'RecursiveArrayTestType'; const DESCRIPTION = 'Testing'; const Schema = new mongoose.Schema({ something: String, }); Schema.add({ whatever: [Schema], }); const ReceivedType = getRidOfThunks(mongooseSchemaToGraphQL({ name: NAME, class: 'GraphQLObjectType', description: DESCRIPTION, schema: Schema, exclude: ['_id'], })); let ExpectedType = new GraphQLObjectType({ name: NAME, description: DESCRIPTION, fields: () => ({ something: { type: GraphQLString }, whatever: { type: new GraphQLList(ExpectedType) }, }), }); ExpectedType = getRidOfThunks(ExpectedType); expect(ReceivedType).toEqual(ExpectedType); });