Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const getNamedType = (opts: Options<NamedTypeNode>): string | number | boolean =
default: {
const foundTypes = opts.types.filter((foundType: TypeItem) => {
if (foundType.types && 'interfaces' in foundType.types)
return foundType.types.interfaces.every((item) => item.name.value === name);
return foundType.types.interfaces.some((item) => item.name.value === name);
return foundType.name === name;
});

Expand Down
84 changes: 75 additions & 9 deletions tests/useImplementingTypes/__snapshots__/spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ exports[`should support useImplementingTypes 1`] = `
"
export const mockAConfig = (overrides?: Partial<AConfig>): AConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
};
};

export const mockField = (overrides?: Partial<Field>): Field => {
return {
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
};
};

export const mockAction = (overrides?: Partial<Action>): Action => {
return {
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : [TestObj.Test],
};
};

Expand All @@ -14,6 +26,9 @@ export const mockA = (overrides?: Partial<A>): A => {
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'ea',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockTestAConfig() || mockTestTwoAConfig(),
configArray: overrides && overrides.hasOwnProperty('configArray') ? overrides.configArray! : [mockTestAConfig() || mockTestTwoAConfig()],
field: overrides && overrides.hasOwnProperty('field') ? overrides.field! : mockTestTwoAConfig(),
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : mockTestAction(),
};
};

Expand All @@ -27,25 +42,44 @@ export const mockB = (overrides?: Partial<B>): B => {

export const mockTestAConfig = (overrides?: Partial<TestAConfig>): TestAConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
active: overrides && overrides.hasOwnProperty('active') ? overrides.active! : true,
};
};

export const mockTestTwoAConfig = (overrides?: Partial<TestTwoAConfig>): TestTwoAConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
username: overrides && overrides.hasOwnProperty('username') ? overrides.username! : 'et',
};
};

export const mockTestAction = (overrides?: Partial<TestAction>): TestAction => {
return {
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : [TestObj.Test],
createdAt: overrides && overrides.hasOwnProperty('createdAt') ? overrides.createdAt! : 'voluptate',
};
};
"
`;

exports[`shouldn't support useImplementingTypes 1`] = `
"
export const mockAConfig = (overrides?: Partial<AConfig>): AConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
};
};

export const mockField = (overrides?: Partial<Field>): Field => {
return {
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
};
};

export const mockAction = (overrides?: Partial<Action>): Action => {
return {
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : [TestObj.Test],
};
};

Expand All @@ -55,6 +89,9 @@ export const mockA = (overrides?: Partial<A>): A => {
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'ea',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockAConfig(),
configArray: overrides && overrides.hasOwnProperty('configArray') ? overrides.configArray! : [mockAConfig()],
field: overrides && overrides.hasOwnProperty('field') ? overrides.field! : mockField(),
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : mockAction(),
};
};

Expand All @@ -68,25 +105,44 @@ export const mockB = (overrides?: Partial<B>): B => {

export const mockTestAConfig = (overrides?: Partial<TestAConfig>): TestAConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
active: overrides && overrides.hasOwnProperty('active') ? overrides.active! : true,
};
};

export const mockTestTwoAConfig = (overrides?: Partial<TestTwoAConfig>): TestTwoAConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
username: overrides && overrides.hasOwnProperty('username') ? overrides.username! : 'et',
};
};

export const mockTestAction = (overrides?: Partial<TestAction>): TestAction => {
return {
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : [TestObj.Test],
createdAt: overrides && overrides.hasOwnProperty('createdAt') ? overrides.createdAt! : 'voluptate',
};
};
"
`;

exports[`support useImplementingTypes with fieldGeneration prop 1`] = `
"
export const mockAConfig = (overrides?: Partial<AConfig>): AConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
};
};

export const mockField = (overrides?: Partial<Field>): Field => {
return {
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
};
};

export const mockAction = (overrides?: Partial<Action>): Action => {
return {
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : [TestObj.Test],
};
};

Expand All @@ -96,6 +152,9 @@ export const mockA = (overrides?: Partial<A>): A => {
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'ea',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : 'Karelle_Kassulke@Carolyne.io',
configArray: overrides && overrides.hasOwnProperty('configArray') ? overrides.configArray! : [mockTestAConfig() || mockTestTwoAConfig()],
field: overrides && overrides.hasOwnProperty('field') ? overrides.field! : mockTestTwoAConfig(),
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : mockTestAction(),
};
};

Expand All @@ -109,16 +168,23 @@ export const mockB = (overrides?: Partial<B>): B => {

export const mockTestAConfig = (overrides?: Partial<TestAConfig>): TestAConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
active: overrides && overrides.hasOwnProperty('active') ? overrides.active! : true,
};
};

export const mockTestTwoAConfig = (overrides?: Partial<TestTwoAConfig>): TestTwoAConfig => {
return {
configTypes: overrides && overrides.hasOwnProperty('configTypes') ? overrides.configTypes! : [ConfigTypes.Test],
testTypes: overrides && overrides.hasOwnProperty('testTypes') ? overrides.testTypes! : [TestObj.Test],
username: overrides && overrides.hasOwnProperty('username') ? overrides.username! : 'et',
};
};

export const mockTestAction = (overrides?: Partial<TestAction>): TestAction => {
return {
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : [TestObj.Test],
createdAt: overrides && overrides.hasOwnProperty('createdAt') ? overrides.createdAt! : 'voluptate',
};
};
"
`;
26 changes: 21 additions & 5 deletions tests/useImplementingTypes/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import { buildSchema } from 'graphql';

export default buildSchema(/* GraphQL */ `
interface AConfig {
configTypes: [configTypes!]!
testTypes: [testObj!]!
}

enum configTypes {
interface Field {
testTypes: [testObj!]!
}

interface Action {
action: [testObj!]!
}

enum testObj {
TEST
TEST2
}
Expand All @@ -15,6 +23,9 @@ export default buildSchema(/* GraphQL */ `
str: String!
obj: B!
config: AConfig!
configArray: [AConfig!]!
field: Field!
action: Action!
}

type B {
Expand All @@ -24,12 +35,17 @@ export default buildSchema(/* GraphQL */ `
}

type TestAConfig implements AConfig {
configTypes: [configTypes!]!
testTypes: [testObj!]!
active: Boolean!
}

type TestTwoAConfig implements AConfig {
configTypes: [configTypes!]!
type TestTwoAConfig implements AConfig & Field {
testTypes: [testObj!]!
username: String!
}

type TestAction implements Action {
action: [testObj!]!
createdAt: String!
}
`);
11 changes: 11 additions & 0 deletions tests/useImplementingTypes/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ it('should support useImplementingTypes', async () => {
"config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockTestAConfig() || mockTestTwoAConfig(),",
);

expect(result).toContain(
"configArray: overrides && overrides.hasOwnProperty('configArray') ? overrides.configArray! : [mockTestAConfig() || mockTestTwoAConfig()],",
);

expect(result).toContain(
"field: overrides && overrides.hasOwnProperty('field') ? overrides.field! : mockTestTwoAConfig(),",
);

expect(result).toContain(
"action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : mockTestAction(),",
);
expect(result).toMatchSnapshot();
});

Expand Down