-
Notifications
You must be signed in to change notification settings - Fork 50
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
Comments
Can you copy - paste your schema code? It seems that you have multiple types or fields with the same name. |
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}`
)); |
@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? |
@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 |
- 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! |
thanks, I will try to figure it out |
This happens when two schemas have a field with the same name that is a reference field - fix RisingStack#84
I defined my models in different files using mongoose, when I try to import all of them I receive this erro:
The text was updated successfully, but these errors were encountered: