VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor

Home Page:http://vulcanjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

collection.addField not working if schema is simpl-schema

EloyID opened this issue · comments

Describe the bug
If I create a collection using a schema which is instance of simpl-schema and then I use addField, it won't appear in GraphQL

To Reproduce
Steps to reproduce the behavior:

  1. Create a collection using simpl-schema in the schema
  2. Use collection.addField
  3. Try to query/filter by this field

Expected behavior
The field to exist

Try this:

  collection.attachSchema({
    addedField1: {
      type: Boolean,
      . . .
    },
    addedField2: {
      type: Object,
      . . .
    },
  });

It's already in the addField function and it used to work in the release of november

Mongo.Collection.prototype.addField = function (fieldOrFieldArray) {
const collection = this;
const fieldSchema = {};
const fieldArray = Array.isArray(fieldOrFieldArray) ? fieldOrFieldArray : [fieldOrFieldArray];
// loop over fields and add them to schema (or extend existing fields)
fieldArray.forEach(function (field) {
fieldSchema[field.fieldName] = field.fieldSchema;
});
// add field schema to collection schema
collection.attachSchema(createSchema(merge(collection.options.schema, fieldSchema)));
};

@EloyID there is a bug in addField that I attempted to fix with a PR but the change was reverted by @SachaG. Here is our discussion about it: #2648 . My solution above is the workaround I am using.