Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema must contain unique named types but contains multiple types named #84

Closed
sibelius opened this issue Jan 23, 2016 · 6 comments · Fixed by #86
Closed

Schema must contain unique named types but contains multiple types named #84

sibelius opened this issue Jan 23, 2016 · 6 comments · Fixed by #86

Comments

@sibelius
Copy link
Contributor

I defined my models in different files using mongoose, when I try to import all of them I receive this erro:

Schema must contain unique named types but contains multiple types named
@tothandras
Copy link
Contributor

Can you copy - paste your schema code? It seems that you have multiple types or fields with the same name.

@sibelius
Copy link
Contributor Author

A.js

import mongoose from 'mongoose';
export const ASchema = new mongoose.Schema({
  name: {
    type: 'String',
  },
},{ collection: 'a'});
export const A = mongoose.model('A', ASchema);

B.js

import mongoose from 'mongoose';
import {ASchema} from './A';

export const BSchema = new mongoose.Schema({
  name: {
    type: String,
  },
  attributes: [ASchema]
}, { collection: 'b'});
export const B = mongoose.model('B', BSchema);

C.js

import mongoose from 'mongoose';
import {ASchema} from './A'

export const CSchema = new mongoose.Schema({
  description: {
    type: String,
  },
  attributes: [ ASchema ],
}, { collection: 'c'});
export const C = mongoose.model('C', CSchema);

server.js

import {getSchema} from '@risingstack/graffiti-mongoose';
import graffiti from '@risingstack/graffiti';
import express from 'express';
import {A} from './A';
import {B} from './B';
import {C} from './C';

const GRAPHQL_PORT = 8080;

mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/brandlovers');
const app = express();
app.use(graffiti.express({
  schema: getSchema([A, B, C])
}));
app.listen(GRAPHQL_PORT, () => console.log(
  `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
));

@tothandras
Copy link
Contributor

@sibeliusseraphini I've got a fix for you. I don't have time right now to finish it, write tests, etc (having an oral exam on Monday). Can it wait until Monday, Tuesday?

@sibelius
Copy link
Contributor Author

@tothandras If you tell me in which file or a little more about this error, I can fork this repo and try to fix it and submit a PR

@tothandras
Copy link
Contributor

type.js line 196:

-        graphQLField.type = new GraphQLList(getType(graffitiModels, {name, description, fields}, newPath, rootType));
+        const fieldNameCapitalized = name.charAt(0).toUpperCase() + name.slice(1);
+        graphQLField.type = new GraphQLList(getType(graffitiModels, {name: `${graphQLType.name}${fieldNameCapitalized}`, description, fields}, newPath, rootType));

Although there is already a field name capitalisation somewhere in the file, you might create a function for that. Thank you!

@sibelius
Copy link
Contributor Author

thanks, I will try to figure it out

sibelius added a commit to sibelius/graffiti-mongoose that referenced this issue Jan 24, 2016
This happens when two schemas have a field with the same name
that is a reference field

- fix RisingStack#84
sibelius added a commit to sibelius/graffiti-mongoose that referenced this issue Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants