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

Duplicate imports generated when overrides export an interface with the same name #340

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions packages/graphqlgen/src/tests/fixtures/override/override-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Foo {
id: string
value: number
}
4 changes: 4 additions & 0 deletions packages/graphqlgen/src/tests/fixtures/override/override-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Foo {
id: string
value: string
}
15 changes: 15 additions & 0 deletions packages/graphqlgen/src/tests/fixtures/override/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type Query {
id: ID!
foo: Foo!
bar: Bar!
}

type Foo {
id: ID
value: Float
}

type Bar {
id: ID
value: String
}
11 changes: 11 additions & 0 deletions packages/graphqlgen/src/tests/fixtures/override/types-flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @flow

export interface Foo {
id: string
value: number
}

export interface Bar {
id: string
value: string
}
9 changes: 9 additions & 0 deletions packages/graphqlgen/src/tests/fixtures/override/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Foo {
id: string
value: number
}

export interface Bar {
id: string
value: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,216 @@ export const resolvers: Resolvers = {
]
`;

exports[`override model same names 1`] = `
"// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import { GraphQLResolveInfo } from \\"graphql\\";
import { Foo } from \\"../../../fixtures/override/override-1\\";
import { Foo } from \\"../../../fixtures/override/override-2\\";
type Context = any;

export namespace QueryResolvers {
export const defaultResolvers = {};

export type IdResolver = (
parent: undefined,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | Promise<string>;

export type FooResolver = (
parent: undefined,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => Foo | Promise<Foo>;

export type BarResolver = (
parent: undefined,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => Foo | Promise<Foo>;

export interface Type {
id: (
parent: undefined,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | Promise<string>;

foo: (
parent: undefined,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => Foo | Promise<Foo>;

bar: (
parent: undefined,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => Foo | Promise<Foo>;
}
}

export namespace FooResolvers {
export const defaultResolvers = {
id: (parent: Foo) => parent.id,
value: (parent: Foo) => parent.value
};

export type IdResolver = (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | null | Promise<string | null>;

export type ValueResolver = (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => number | null | Promise<number | null>;

export interface Type {
id: (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | null | Promise<string | null>;

value: (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => number | null | Promise<number | null>;
}
}

export namespace BarResolvers {
export const defaultResolvers = {
id: (parent: Foo) => parent.id,
value: (parent: Foo) => parent.value
};

export type IdResolver = (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | null | Promise<string | null>;

export type ValueResolver = (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | null | Promise<string | null>;

export interface Type {
id: (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | null | Promise<string | null>;

value: (
parent: Foo,
args: {},
ctx: Context,
info: GraphQLResolveInfo
) => string | null | Promise<string | null>;
}
}

export interface Resolvers {
Query: QueryResolvers.Type;
Foo: FooResolvers.Type;
Bar: BarResolvers.Type;
}
"
`;

exports[`override model same names 2`] = `
Array [
Object {
"code": "// This resolver file was scaffolded by github.com/prisma/graphqlgen, DO NOT EDIT.
// Please do not import this file directly but copy & paste to your application code.

import { FooResolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

export const Foo: FooResolvers.Type = {
...FooResolvers.defaultResolvers
};
",
"force": false,
"path": "Foo.ts",
},
Object {
"code": "// This resolver file was scaffolded by github.com/prisma/graphqlgen, DO NOT EDIT.
// Please do not import this file directly but copy & paste to your application code.

import { BarResolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

export const Bar: BarResolvers.Type = {
...BarResolvers.defaultResolvers
};
",
"force": false,
"path": "Bar.ts",
},
Object {
"code": "// This resolver file was scaffolded by github.com/prisma/graphqlgen, DO NOT EDIT.
// Please do not import this file directly but copy & paste to your application code.

import { QueryResolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

export const Query: QueryResolvers.Type = {
...QueryResolvers.defaultResolvers,
id: (parent, args, ctx) => {
throw new Error(\\"Resolver not implemented\\");
},
foo: (parent, args, ctx) => {
throw new Error(\\"Resolver not implemented\\");
},
bar: (parent, args, ctx) => {
throw new Error(\\"Resolver not implemented\\");
}
};
",
"force": false,
"path": "Query.ts",
},
Object {
"code": "// This resolver file was scaffolded by github.com/prisma/graphqlgen, DO NOT EDIT.
// Please do not import this file directly but copy & paste to your application code.

import { Resolvers } from \\"[TEMPLATE-INTERFACES-PATH]\\";

import { Query } from \\"./Query\\";
import { Foo } from \\"./Foo\\";
import { Bar } from \\"./Bar\\";

export const resolvers: Resolvers = {
Query,
Foo,
Bar
};
",
"force": false,
"path": "index.ts",
},
]
`;

exports[`subscription 1`] = `
"// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

Expand Down
19 changes: 19 additions & 0 deletions packages/graphqlgen/src/tests/typescript/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,22 @@ test('override model', async () => {
},
})
})

test('override model same names', async () => {
testGeneration({
language,
schema: relative('../fixtures/override/schema.graphql'),
models: {
files: [relative('../fixtures/override/types.ts')],
override: {
Foo: `${relative('../fixtures/override/override-1.ts')}:Foo`,
Bar: `${relative('../fixtures/override/override-2.ts')}:Foo`,
},
},
output: relative('./generated/override/graphqlgen.ts'),
['resolver-scaffolding']: {
output: relative('./tmp/override/'),
layout: 'file-per-type',
},
})
})