Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for useImplementingTypes #125

Merged
merged 10 commits into from
Apr 11, 2023

Conversation

maordaniel
Copy link
Contributor

@maordaniel maordaniel commented Mar 23, 2023

Add support for useImplementingTypes GraphQL codegen configuration.

  • When a GraphQL interface is used for a field, this flag will use the implementing types, instead of the interface itself.

src/index.ts Outdated
Comment on lines 342 to 348
return `relationshipsToOmit.has('${casedName}') ? {} as ${casedName} : ${toMockName(
name,
casedName,
opts.prefix,
)}({}, relationshipsToOmit)`;
} else {
return handleValueGeneration(opts, null, () => `${toMockName(name, casedName, opts.prefix)}()`);
return `${toMockName(name, casedName, opts.prefix)}()`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful, this handleValueGeneration was added this week, are you sure it needs to be removed?

Copy link
Contributor Author

@maordaniel maordaniel Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, sorry about that.
I will fix it.
do i need to use "handleValueGeneration" in getNamedImplementType func? @ardeois

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes probably, handleValueGeneration is necessary when you use config fieldGeneration
Here is a unit test example. You should add one to make sure it works with implementing types

it('uses per field generation if field name matches', async () => {
const result = await plugin(testSchema, [], {
...config,
fieldGeneration: {
A: { email: 'internet.email' },
},
});
expect(result).toBeDefined();
// Custom generation in type A
expect(result).toContain(
"email: overrides && overrides.hasOwnProperty('email') ? overrides.email! : faker['internet']['email']()",
);
// Original generation in type B (unchanged)
expect(result).toContain(
"email: overrides && overrides.hasOwnProperty('email') ? overrides.email! : faker['lorem']['sentence'](),",
);
expect(result).toMatchSnapshot();
});

Copy link
Contributor Author

@maordaniel maordaniel Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is related, nor is it necessary.
if someone using fieldGeneration, why use useImplementingTypes as well?
This is contrary to the idea. @ardeois

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example:

const result = await plugin(testSchema, [], { 
         ...config, 
         fieldGeneration: { 
             A: { config: 'internet.config' }, 
         }, 
     }); 
    
 expect(result).toContain(
        "config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : internet.config() || internet.config(),",
    );

Copy link
Contributor Author

@maordaniel maordaniel Mar 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've fix it.
Now if the prop useimplementingtypes is true and the fieldgeneration is not empty, the code will ignore the implant types.. i added test about that @ardeois

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@ardeois
Copy link
Owner

ardeois commented Mar 23, 2023

Thanks for implementing this @maordaniel

I've got a few comments and the unit tests are failing

@maordaniel
Copy link
Contributor Author

maordaniel commented Mar 23, 2023

Thanks for implementing this @maordaniel

I've got a few comments and the unit tests are failing

Thank you for reviewing @ardeois
The unit tests that fail are not related to changes in my pr..

@ardeois
Copy link
Owner

ardeois commented Mar 23, 2023

@maordaniel tests related to your code are now failing
CleanShot 2023-03-23 at 15 36 27

@maordaniel maordaniel force-pushed the maord-support-useImplementingTypes branch from 84f818e to 8f12972 Compare March 25, 2023 01:39
@maordaniel
Copy link
Contributor Author

maordaniel commented Mar 25, 2023

@maordaniel tests related to your code are now failing
CleanShot 2023-03-23 at 15 36 27

Fixed and i added one more test @ardeois

@maordaniel maordaniel requested a review from ardeois March 25, 2023 09:58
Copy link
Owner

@ardeois ardeois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, I got quite busy these last few days.
I tried to do an in depth review and found potential issues.
Let me know what you think

Thanks again for the help !

tests/useImplementingTypes/__snapshots__/spec.ts.snap Outdated Show resolved Hide resolved
tests/useImplementingTypes/__snapshots__/spec.ts.snap Outdated Show resolved Hide resolved
tests/useImplementingTypes/__snapshots__/spec.ts.snap Outdated Show resolved Hide resolved
tests/useImplementingTypes/__snapshots__/spec.ts.snap Outdated Show resolved Hide resolved
tests/useImplementingTypes/spec.ts Show resolved Hide resolved
@maordaniel maordaniel requested a review from ardeois April 2, 2023 00:57
@maordaniel
Copy link
Contributor Author

maordaniel commented Apr 2, 2023

Sorry for the late review, I got quite busy these last few days. I tried to do an in depth review and found potential issues. Let me know what you think

Thanks again for the help !

Hi Ardeois,
hope you are well.
i've fixed the issues you mentioned.
no problem, thanks 🙏
@ardeois

Copy link
Owner

@ardeois ardeois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! thanks for the updates

@ardeois ardeois self-assigned this Apr 3, 2023
@ardeois ardeois added the minor Increment the minor version when merged label Apr 3, 2023
@maordaniel maordaniel requested a review from ardeois April 3, 2023 16:37
@maordaniel
Copy link
Contributor Author

maordaniel commented Apr 3, 2023

Looks good ! thanks for the updates

Thanks a lot,
Really appreciate that ! @ardeois

I updated readme file and the snapshot for the test, pls approve this again.

@maordaniel
Copy link
Contributor Author

Hi @ardeois ,
When are you going to merge it?

Thanks

@ardeois ardeois merged commit d1e1716 into ardeois:main Apr 11, 2023
@ardeois
Copy link
Owner

ardeois commented Apr 11, 2023

Hi @ardeois ,
When are you going to merge it?

Thanks

Sorry about that @maordaniel I forgot
It's merged !

@maordaniel
Copy link
Contributor Author

Thanks a lot! 🙏🏻 @ardeois

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants