Skip to content

Commit

Permalink
feat(generator): minor fixes for code generation for schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Dec 14, 2016
1 parent f04b3a0 commit f69f375
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ const isArray = (type: GraphQLType): boolean => {
return (type.toString()).indexOf('[') > -1;
};

const getTypeName = (models: ModelsObject, type: GraphQLType) => {
const getTypeName = (type: GraphQLType) => {
const name = (type.toString()).replace(/[\[\]!]/g, '');

if (primitivesMap[name]) {
return primitivesMap[name];
}
else if (models[name]) {
return models[name].name;
}
else {
return name;
}
};

export const prepareCodegen = (schema: GraphQLSchema, documents: Source[], typesMap: TypeMap = schema.getTypeMap(), models: ModelsObject = {}): Codegen => {
export const prepareCodegen = (schema: GraphQLSchema, documents: Source[]): Codegen => {
let models: ModelsObject = {};
let typesMap: TypeMap = schema.getTypeMap();

Object.keys(typesMap).forEach(typeName => {
const type: GraphQLType = typesMap[typeName];
let currentType: Model = {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const prepareCodegen = (schema: GraphQLSchema, documents: Source[], types
.map<Field>((field: GraphQLFieldDefinition) => {
return {
name: field.name,
type: getTypeName(models, field.type),
type: getTypeName(field.type),
isArray: isArray(field.type),
isRequired: isRequired(field.type),
isNullable: false
Expand Down

0 comments on commit f69f375

Please sign in to comment.