Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

collection.addField not working if schema is simpl-schema #2708

Open
EloyID opened this issue Apr 6, 2021 · 3 comments
Open

collection.addField not working if schema is simpl-schema #2708

EloyID opened this issue Apr 6, 2021 · 3 comments

Comments

@EloyID
Copy link
Contributor

EloyID commented Apr 6, 2021

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

@ErikDakoda
Copy link
Contributor

Try this:

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

@EloyID
Copy link
Contributor Author

EloyID commented Apr 6, 2021

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)));
};

@ErikDakoda
Copy link
Contributor

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants