Skip to content

Commit

Permalink
fix(FieldConverter): Return field type for mongoose references instea…
Browse files Browse the repository at this point in the history
…d of abstract GQLReference type

closes #3
  • Loading branch information
nodkz committed Oct 20, 2016
1 parent 0bc78dd commit 9edc5a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/__tests__/fieldConverter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
enumToGraphQL,
documentArrayToGraphQL,
mixedToGraphQL,
referenceToGraphQL,
} from '../fieldsConverter';
import { composeWithMongoose } from '../composeWithMongoose';
import GraphQLMongoID from '../types/mongoid';
Expand Down Expand Up @@ -241,8 +242,8 @@ describe('fieldConverter', () => {
});

describe('referenceToGraphQL()', () => {
xit('', () => {

it('should return type of field', () => {
expect(referenceToGraphQL(fields.user)).equal(GraphQLMongoID);
});
});
});
21 changes: 10 additions & 11 deletions src/fieldsConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
GraphQLBuffer,
GraphQLGeneric,
GraphQLJSON,
GQLReference,
} from 'graphql-compose';

import {
Expand Down Expand Up @@ -148,7 +147,7 @@ export function convertModelToGraphQL(
const mongooseFields = getFieldsFromModel(model, typeName);
const graphqlFields = {};

Object.keys(mongooseFields).forEach(fieldName => {
Object.keys(mongooseFields).forEach((fieldName) => {
const mongooseField:MongooseFieldT = mongooseFields[fieldName];
graphqlFields[fieldName] = {
type: convertFieldToGraphQL(mongooseField, typeName),
Expand Down Expand Up @@ -232,7 +231,7 @@ export function deriveComplexType(field: MongooseFieldT): ComplexTypesT {
function removePseudoIdField(typeComposer: TypeComposer): void {
// remove pseudo object id mongoose field
const gqFields = typeComposer.getFields();
Object.keys(gqFields).forEach(name => {
Object.keys(gqFields).forEach((name) => {
if (gqFields[name].type === GraphQLMongoID) {
typeComposer.removeField(name);
}
Expand Down Expand Up @@ -345,14 +344,14 @@ export function referenceToGraphQL(
+ 'Correct field should has mongoose-type `ObjectID`');
}

const refModelName = objectPath.get(field, 'options.ref');
if (refModelName) {
return GQLReference;
// throw new Error('Mongoose REFERENCE to graphQL TYPE not implemented yet. '
// + `Field ${_getFieldName(field)}`);
// Storage.UnresolvedRefs.setSubKey(parentTypeName, fieldName, { refModelName });
// return GraphQLReference;
}
// const refModelName = objectPath.get(field, 'options.ref');
// if (refModelName) {
// return GQLReference;
// // throw new Error('Mongoose REFERENCE to graphQL TYPE not implemented yet. '
// // + `Field ${_getFieldName(field)}`);
// // Storage.UnresolvedRefs.setSubKey(parentTypeName, fieldName, { refModelName });
// // return GraphQLReference;
// }

// this is mongo id field
return scalarToGraphQL(field, prefix);
Expand Down

0 comments on commit 9edc5a8

Please sign in to comment.