Skip to content
Permalink
Browse files
fix(codegen-schema): create subscription fields if mutations disabled
  • Loading branch information
Enda Phelan committed Sep 23, 2020
1 parent dfce342 commit 212eb7a3e718eb102c226c237ce2448a2aa26898
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
@@ -161,7 +161,7 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
buildSubscriptionFilterType(schemaComposer, modelType);

const subscriptionFields = {}
if (model.crudOptions.subCreate && model.crudOptions.create) {
if (model.crudOptions.subCreate) {
const operation = getSubscriptionName(name, GraphbackOperationType.CREATE)

const filterInputName = getInputTypeName(name, GraphbackOperationType.SUBSCRIPTION_CREATE)
@@ -176,7 +176,7 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
}
};
}
if (model.crudOptions.subUpdate && model.crudOptions.update) {
if (model.crudOptions.subUpdate) {
const operation = getSubscriptionName(name, GraphbackOperationType.UPDATE)

const filterInputName = getInputTypeName(name, GraphbackOperationType.SUBSCRIPTION_UPDATE)
@@ -191,7 +191,7 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
}
};
}
if (model.crudOptions.subDelete && model.crudOptions.delete) {
if (model.crudOptions.subDelete) {
const operation = getSubscriptionName(name, GraphbackOperationType.DELETE)

const filterInputName = getInputTypeName(name, GraphbackOperationType.SUBSCRIPTION_DELETE)
@@ -1,7 +1,7 @@
/* eslint-disable max-lines */
import { readFileSync } from 'fs';
import { buildSchema, printSchema, GraphQLObjectType, assertInputObjectType } from 'graphql';
import { GraphbackCoreMetadata, printSchemaWithDirectives, GraphbackPluginEngine, metadataMap } from '@graphback/core';
import { GraphbackCoreMetadata, printSchemaWithDirectives, GraphbackPluginEngine, metadataMap, GraphbackCRUDGeneratorConfig } from '@graphback/core';

import { SchemaCRUDPlugin } from '../src/SchemaCRUDPlugin';

@@ -72,6 +72,29 @@ test('Test snapshot config js', async () => {
expect(printSchema(schema)).toMatchSnapshot();
});

test('Create subscription fields when mutations are disabled', () => {
const crudMethods: GraphbackCRUDGeneratorConfig = {
create: false,
update: false,
delete: false
};

const schemaGenerator = new SchemaCRUDPlugin()
const metadata = new GraphbackCoreMetadata({
crudMethods
}, buildSchema(`
"""@model"""
type Note {
id: ID!
title: String
}
`))
const schema = schemaGenerator.transformSchema(metadata);
expect(Object.keys(schema.getSubscriptionType().getFields())).toEqual(['newNote', 'updatedNote', 'deletedNote']);
expect(schema.getMutationType()).toBeUndefined();
expect(printSchema(schema)).toMatchSnapshot();
})

test('Test one side relationship schema query type generation', async () => {
const defautConfig = {
"create": false,
@@ -1,5 +1,86 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Create subscription fields when mutations are disabled 1`] = `
"type Query {
getNote(id: ID!): Note
findNotes(filter: NoteFilter, page: PageRequest, orderBy: OrderByInput): NoteResultList!
}
\\"\\"\\"@model\\"\\"\\"
type Note {
id: ID!
title: String
}
type NoteResultList {
items: [Note]!
offset: Int
limit: Int
count: Int
}
input NoteFilter {
id: IDInput
title: StringInput
and: [NoteFilter!]
or: [NoteFilter!]
not: NoteFilter
}
input IDInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
in: [ID!]
}
input StringInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
in: [String!]
contains: String
startsWith: String
endsWith: String
}
input PageRequest {
limit: Int
offset: Int
}
input OrderByInput {
field: String!
order: SortDirectionEnum = ASC
}
enum SortDirectionEnum {
DESC
ASC
}
type Subscription {
newNote(filter: NoteSubscriptionFilter): Note!
updatedNote(filter: NoteSubscriptionFilter): Note!
deletedNote(filter: NoteSubscriptionFilter): Note!
}
input NoteSubscriptionFilter {
and: [NoteSubscriptionFilter!]
or: [NoteSubscriptionFilter!]
not: NoteSubscriptionFilter
id: IDInput
title: StringInput
}
"
`;

exports[`Creates CRUD resolvers for models 1`] = `
Object {
"Comment": Object {

0 comments on commit 212eb7a

Please sign in to comment.