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

feat: attach .js extension to all relative/absolute file imports/exports #8034

Merged
merged 6 commits into from
Jul 6, 2022

Conversation

n1ru4l
Copy link
Collaborator

@n1ru4l n1ru4l commented Jul 5, 2022

Closes #8022
Closes #8034

@changeset-bot
Copy link

changeset-bot bot commented Jul 5, 2022

🦋 Changeset detected

Latest commit: 8eebab3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@graphql-codegen/visitor-plugin-common Minor
@graphql-codegen/gql-tag-operations-preset Minor
@graphql-codegen/near-operation-file-preset Minor
@graphql-codegen/typescript-oclif Minor
@graphql-codegen/flow Patch
@graphql-codegen/flow-operations Patch
@graphql-codegen/flow-resolvers Patch
@graphql-codegen/java-apollo-android Patch
@graphql-codegen/java-common Patch
@graphql-codegen/java Patch
@graphql-codegen/kotlin Patch
@graphql-codegen/java-resolvers Patch
@graphql-codegen/typescript-apollo-angular Patch
@graphql-codegen/typescript-apollo-client-helpers Patch
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/typescript-generic-sdk Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-graphql-request Patch
@graphql-codegen/typescript-jit-sdk Patch
@graphql-codegen/typescript-mongodb Patch
@graphql-codegen/typescript-msw Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typescript-react-offix Patch
@graphql-codegen/typescript-react-apollo Patch
@graphql-codegen/typescript-react-query Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typescript-rtk-query Patch
@graphql-codegen/typescript-stencil-apollo Patch
@graphql-codegen/typescript-type-graphql Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/typescript Patch
@graphql-codegen/typescript-urql-graphcache Patch
@graphql-codegen/urql-svelte-operations-store Patch
@graphql-codegen/typescript-urql Patch
@graphql-codegen/typescript-vue-apollo-smart-ops Patch
@graphql-codegen/typescript-vue-apollo Patch
@graphql-codegen/typescript-vue-urql Patch
@graphql-codegen/jsdoc Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/import-types-preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
graphql-code-generator ✅ Ready (Inspect) Visit Preview Jul 6, 2022 at 1:13PM (UTC)

@n1ru4l n1ru4l changed the title fix: attach .js extension to all emitted file imports/exports fix: attach .js extension to all relative file imports/exports Jul 5, 2022
@n1ru4l n1ru4l changed the title fix: attach .js extension to all relative file imports/exports fix: attach .js extension to all relative/absolute file imports/exports Jul 5, 2022
@theguild-bot
Copy link
Collaborator

theguild-bot commented Jul 5, 2022

The latest changes of this PR are available as alpha in npm (based on the declared changesets):

@graphql-codegen/c-sharp@4.2.16-alpha-98f983dcf.0
@graphql-codegen/c-sharp-common@0.0.1-alpha-98f983dcf.0
@graphql-codegen/c-sharp-operations@2.2.15-alpha-98f983dcf.0
@graphql-codegen/flow@2.2.15-alpha-98f983dcf.0
@graphql-codegen/flow-operations@2.2.15-alpha-98f983dcf.0
@graphql-codegen/flow-resolvers@2.2.16-alpha-98f983dcf.0
@graphql-codegen/java-apollo-android@2.2.15-alpha-98f983dcf.0
@graphql-codegen/java-common@2.1.22-alpha-98f983dcf.0
@graphql-codegen/java@3.2.16-alpha-98f983dcf.0
@graphql-codegen/kotlin@2.2.16-alpha-98f983dcf.0
@graphql-codegen/java-resolvers@2.2.15-alpha-98f983dcf.0
@graphql-codegen/introspection@2.1.2-alpha-98f983dcf.0
@graphql-codegen/jsdoc@2.2.15-alpha-98f983dcf.0
@graphql-codegen/visitor-plugin-common@2.11.0-alpha-98f983dcf.0
@graphql-codegen/typescript-apollo-angular@3.4.14-alpha-98f983dcf.0
@graphql-codegen/typescript-apollo-client-helpers@2.1.22-alpha-98f983dcf.0
@graphql-codegen/typescript-document-nodes@2.2.15-alpha-98f983dcf.0
@graphql-codegen/typescript-generic-sdk@2.3.14-alpha-98f983dcf.0
@graphql-codegen/gql-tag-operations@1.2.18-alpha-98f983dcf.0
@graphql-codegen/typescript-graphql-apollo@1.1.2-alpha-98f983dcf.0
@graphql-codegen/typescript-graphql-request@4.4.12-alpha-98f983dcf.0
@graphql-codegen/typescript-jit-sdk@2.0.13-alpha-98f983dcf.0
@graphql-codegen/typescript-mongodb@2.3.13-alpha-98f983dcf.0
@graphql-codegen/typescript-msw@1.0.14-alpha-98f983dcf.0
@graphql-codegen/typescript-oclif@2.3.0-alpha-98f983dcf.0
@graphql-codegen/typescript-operations@2.4.4-alpha-98f983dcf.0
@graphql-codegen/typescript-react-apollo@3.2.18-alpha-98f983dcf.0
@graphql-codegen/typescript-react-offix@2.2.15-alpha-98f983dcf.0
@graphql-codegen/typescript-react-query@3.5.16-alpha-98f983dcf.0
@graphql-codegen/typescript-resolvers@2.6.8-alpha-98f983dcf.0
@graphql-codegen/typescript-rtk-query@2.2.16-alpha-98f983dcf.0
@graphql-codegen/typescript-stencil-apollo@2.2.15-alpha-98f983dcf.0
@graphql-codegen/typescript-type-graphql@2.2.16-alpha-98f983dcf.0
@graphql-codegen/typed-document-node@2.2.15-alpha-98f983dcf.0
@graphql-codegen/typescript@2.6.1-alpha-98f983dcf.0
@graphql-codegen/typescript-urql@3.5.14-alpha-98f983dcf.0
@graphql-codegen/typescript-urql-graphcache@2.2.18-alpha-98f983dcf.0
@graphql-codegen/urql-svelte-operations-store@1.1.22-alpha-98f983dcf.0
@graphql-codegen/typescript-vue-apollo@3.2.16-alpha-98f983dcf.0
@graphql-codegen/typescript-vue-apollo-smart-ops@2.2.15-alpha-98f983dcf.0
@graphql-codegen/typescript-vue-urql@2.2.16-alpha-98f983dcf.0
@graphql-codegen/gql-tag-operations-preset@1.5.0-alpha-98f983dcf.0
@graphql-codegen/graphql-modules-preset@2.3.15-alpha-98f983dcf.0
@graphql-codegen/import-types-preset@2.1.22-alpha-98f983dcf.0
@graphql-codegen/near-operation-file-preset@2.3.0-alpha-98f983dcf.0

@n1ru4l n1ru4l requested review from gilgardosh, dotansimha, kamilkisiela and saihaj and removed request for gilgardosh, dotansimha and kamilkisiela July 5, 2022 13:50
@n1ru4l n1ru4l changed the title fix: attach .js extension to all relative/absolute file imports/exports feat: attach .js extension to all relative/absolute file imports/exports Jul 5, 2022
@gilgardosh
Copy link
Collaborator

@n1ru4l Is the extension needed here also?

): typeof import('./graphql').FooDocument;
export function gql(
source: '\n fragment Lel on Tweet {\n id\n body\n }\n'
): typeof import('./graphql').LelFragmentDoc;
export function gql(
source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n'
): typeof import('./graphql').BarDocument;

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Jul 6, 2022

@n1ru4l Is the extension needed here also?

): typeof import('./graphql').FooDocument;
export function gql(
source: '\n fragment Lel on Tweet {\n id\n body\n }\n'
): typeof import('./graphql').LelFragmentDoc;
export function gql(
source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n'
): typeof import('./graphql').BarDocument;

Good catch, fixed it in 985d167

@gilgardosh
Copy link
Collaborator

gilgardosh commented Jul 6, 2022

hmm I think extensions should also be added to config inputs, right?

importBaseApiFrom: '../../packages/plugins/typescript/rtk-query/tests/baseApi'

otherwise files being generated without it

import { api } from '../../packages/plugins/typescript/rtk-query/tests/baseApi';

@gilgardosh
Copy link
Collaborator

this should be rethinked:

const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, '');

extension are removed, for example

baseTypesPath: types.ts

resolves into
import * as Types from '../types';

Copy link
Owner

@dotansimha dotansimha left a comment

Choose a reason for hiding this comment

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

@n1ru4l do we have any concerns about breaking changes? older TS version or anything like that? (in the generated files, i mean)

@gilgardosh
Copy link
Collaborator

const { handlerPath = '../../handler' } = rawConfig;

default needs extension

@gilgardosh
Copy link
Collaborator

"import { AuthenticatedResolver as ResolverFnAuthenticated } from '../resolver-types.ts';"

also, in this file, look for assurances of ../entities

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Jul 6, 2022

graphql-code-generator/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts

I think this is fine, as it is configured through a user-provided configuration. (

authenticated: `../resolver-types.ts#AuthenticatedResolver`,
).

I added a note to the changeset for instructing people to adjust their mappers etc.

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Jul 6, 2022

@n1ru4l do we have any concerns about breaking changes? older TS version or anything like that? (in the generated files, i mean)

.js worked in all previous TS version afaik

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Jul 8, 2022

Apparently, this broke Next.js... #8065

n1ru4l added a commit that referenced this pull request Jul 8, 2022
n1ru4l added a commit that referenced this pull request Jul 9, 2022
…rts/exports" (#8068)

* Revert "feat: attach .js extension to all relative/absolute file imports/exports (#8034)"

This reverts commit 68bb30e.

* chore: add changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change plugins to attach .js extension to emitted code
6 participants