arackaf / mongo-graphql-starter

Creates a fully functioning, performant, extensible GraphQL endpoint from a Mongo DB. Supports middleware, Mongo 4 transactions.
MIT License
423 stars 29 forks source link

X has many X's and belongs to one X: XMetadata has already been declared #80

Closed peebles closed 3 years ago

peebles commented 3 years ago

I have a schema where Organizations belong to an Organization (parent) and have many child Organizations:

export const Organization = {
  table: "Organization",
  fields: {
    name: StringType,
    description: StringType,
    organizationId: MongoIdType,
  },
  relationships: {
    organization: {
      get type() { return Organization },
      fkField: 'organizationId',
      keyField: '_id',
      oneToOne: true,
    },
    organizations: {
      get type() { return Organization },
      fkField: '_id',
      keyField: 'organizationId',
      oneToMany: true,
    },
}

The Organization.resolvers.js file ends up with:

...
import OrganizationMetadata from "./Organization";
import OrganizationMetadata from "../Organization/Organization";
...

which generates: SyntaxError: Identifier 'OrganizationMetadata' has already been declared

If I delete one of those two lines, everything I've tried works so far ... at least queries. I have not yet tried mutations with related data.

arackaf commented 3 years ago

Oh yikes - thanks for the bug - I’ll fix in the next few days

arackaf commented 3 years ago

Fixed in https://github.com/arackaf/mongo-graphql-starter/releases/tag/0.11.7