Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Remove filtering from model map #300

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions packages/graphqlgen/src/generators/ts-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
renderEnums,
groupModelsNameByImportPath,
} from './common'
import { TypeAliasDefinition } from '../introspection/types'
import { upperFirst } from '../utils'

export function format(code: string, options: prettier.Options = {}) {
Expand Down Expand Up @@ -68,7 +67,7 @@ export function generate(args: GenerateArgs): string {

return `\
${renderHeader(args)}

${renderEnums(args)}

${renderNamespaces(args, typeToInputTypeAssociation, inputTypesMap)}
Expand All @@ -80,14 +79,6 @@ export function generate(args: GenerateArgs): string {

function renderHeader(args: GenerateArgs): string {
const modelsToImport = Object.keys(args.modelMap)
.filter(modelName => {
const modelDef = args.modelMap[modelName].definition

return !(
modelDef.kind === 'TypeAliasDefinition' &&
(modelDef as TypeAliasDefinition).isEnum
)
})
.map(modelName => args.modelMap[modelName])
const modelsByImportPaths = groupModelsNameByImportPath(modelsToImport)

Expand Down
15 changes: 10 additions & 5 deletions packages/graphqlgen/src/tests/fixtures/enum/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
type User {
id: ID!
name: String!
enumAnnotation: EnumAnnotation!
enumAsUnionType: EnumAsUnionType!
color: Color!
role: Role!
permissions: Permissions!
}

enum EnumAnnotation {
type Permissions {
isAdmin: Boolean
}

enum Role {
EDITOR
COLLABORATOR
}

enum EnumAsUnionType {
enum Color {
RED
GREEN
BLUE
}

type Query {
createUser(name: String!, type: EnumAnnotation!): User
createUser(name: String!, type: Role!): User
}
9 changes: 5 additions & 4 deletions packages/graphqlgen/src/tests/fixtures/enum/types-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
export interface User {
id: string,
name: string,
enumAnnotation: EnumAnnotation,
enumAsUnionType: EnumAsUnionType,
color: Color,
role: Permissions,
permissions: Permissions,
}

type EnumAnnotation = 'ADMIN' | 'EDITOR' | 'COLLABORATOR'
type EnumAsUnionType = 'RED' | 'GREEN' | 'BLUE'
export type Permissions = 'ADMIN' | 'EDITOR' | 'COLLABORATOR'
export type Color = 'RED' | 'GREEN' | 'BLUE'
9 changes: 5 additions & 4 deletions packages/graphqlgen/src/tests/fixtures/enum/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export interface User {
id: string
name: string
enumAnnotation: EnumAnnotation
enumAsUnionType: EnumAsUnionType
color: Color
role: Permissions
permissions: Permissions
}

enum EnumAnnotation {
export enum Permissions {
ADMIN,
EDITOR,
COLLABORATOR,
}

type EnumAsUnionType = 'RED' | 'GREEN' | 'BLUE'
export type Color = 'RED' | 'GREEN' | 'BLUE'
83 changes: 68 additions & 15 deletions packages/graphqlgen/src/tests/flow/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ exports[`basic enum 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { User } from \\"../../../fixtures/enum/types-flow\\";
import type { User, Permissions } from \\"../../../fixtures/enum/types-flow\\";
type Context = any;

type EnumAnnotation = \\"EDITOR\\" | \\"COLLABORATOR\\";
type EnumAsUnionType = \\"RED\\" | \\"GREEN\\" | \\"BLUE\\";
type Role = \\"EDITOR\\" | \\"COLLABORATOR\\";
type Color = \\"RED\\" | \\"GREEN\\" | \\"BLUE\\";

// Types for Query
export const Query_defaultResolvers = {};

export interface Query_Args_CreateUser {
name: string;
type: EnumAnnotation;
type: Role;
}

export type Query_CreateUser_Resolver = (
Expand All @@ -39,7 +39,8 @@ export interface Query_Resolvers {
export const User_defaultResolvers = {
id: (parent: User) => parent.id,
name: (parent: User) => parent.name,
enumAsUnionType: (parent: User) => parent.enumAsUnionType
color: (parent: User) => parent.color,
permissions: (parent: User) => parent.permissions
};

export type User_Id_Resolver = (
Expand All @@ -56,19 +57,26 @@ export type User_Name_Resolver = (
info: GraphQLResolveInfo
) => string | Promise<string>;

export type User_EnumAnnotation_Resolver = (
export type User_Color_Resolver = (
parent: User,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => EnumAnnotation | Promise<EnumAnnotation>;
) => Color | Promise<Color>;

export type User_EnumAsUnionType_Resolver = (
export type User_Role_Resolver = (
parent: User,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => EnumAsUnionType | Promise<EnumAsUnionType>;
) => Role | Promise<Role>;

export type User_Permissions_Resolver = (
parent: User,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => Permissions | Promise<Permissions>;

export interface User_Resolvers {
id: (
Expand All @@ -85,24 +93,51 @@ export interface User_Resolvers {
info: GraphQLResolveInfo
) => string | Promise<string>;

enumAnnotation: (
color: (
parent: User,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => EnumAnnotation | Promise<EnumAnnotation>;
) => Color | Promise<Color>;

enumAsUnionType: (
role: (
parent: User,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => EnumAsUnionType | Promise<EnumAsUnionType>;
) => Role | Promise<Role>;

permissions: (
parent: User,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => Permissions | Promise<Permissions>;
}

// Types for Permissions
export const Permissions_defaultResolvers = {};

export type Permissions_IsAdmin_Resolver = (
parent: Permissions,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => boolean | null | Promise<boolean | null>;

export interface Permissions_Resolvers {
isAdmin: (
parent: Permissions,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => boolean | null | Promise<boolean | null>;
}

export interface Resolvers {
Query: Query_Resolvers;
User: User_Resolvers;
Permissions: Permissions_Resolvers;
}
"
`;
Expand All @@ -117,7 +152,7 @@ import type { User_Resolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";
export const User: User_Resolvers = {
...User_defaultResolvers,

enumAnnotation: (parent, args, ctx, info) => {
role: (parent, args, ctx, info) => {
throw new Error(\\"Resolver not implemented\\");
}
};
Expand All @@ -127,6 +162,22 @@ export const User: User_Resolvers = {
},
Object {
"code": "/* @flow */
import { Permissions_defaultResolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";
import type { Permissions_Resolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

export const Permissions: Permissions_Resolvers = {
...Permissions_defaultResolvers,

isAdmin: (parent, args, ctx, info) => {
throw new Error(\\"Resolver not implemented\\");
}
};
",
"force": false,
"path": "Permissions.js",
},
Object {
"code": "/* @flow */
import type { Query_Resolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

export const Query: Query_Resolvers = {
Expand All @@ -147,10 +198,12 @@ import type { Resolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

import { Query } from \\"./Query\\";
import { User } from \\"./User\\";
import { Permissions } from \\"./Permissions\\";

export const resolvers: Resolvers = {
Query,
User
User,
Permissions
};
",
"force": false,
Expand Down
Loading