Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

wip: collect inline require statements and convert them to top level imports #269

Merged
merged 6 commits into from
Aug 2, 2021

Conversation

n1ru4l
Copy link
Member

@n1ru4l n1ru4l commented Feb 11, 2021

It might be possible that this should be better off within relay. however, this works great for my use-cases as a quick fix.

Example output:

/* tslint:disable */
/* eslint-disable */
// @ts-nocheck

+ import tokenInfoSideBar_MoreNotesQuery from "./tokenInfoSideBar_MoreNotesQuery.graphql"
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type tokenInfoSideBar_NotesFragment = {
  readonly notes: {
    readonly __id: string;
    readonly edges: ReadonlyArray<{
      readonly node: {
        readonly id: string;
        readonly documentId: string;
        readonly title: string;
      };
    }>;
    readonly pageInfo: {
      readonly endCursor: string;
      readonly hasNextPage: boolean;
    };
  };
  readonly " $refType": "tokenInfoSideBar_NotesFragment";
};
export type tokenInfoSideBar_NotesFragment$data = tokenInfoSideBar_NotesFragment;
export type tokenInfoSideBar_NotesFragment$key = {
  readonly " $data"?: tokenInfoSideBar_NotesFragment$data;
  readonly " $fragmentRefs": FragmentRefs<"tokenInfoSideBar_NotesFragment">;
};

const node: ReaderFragment = (function () {
  var v0 = ["notes"];
  return {
    argumentDefinitions: [
      {
        defaultValue: 20,
        kind: "LocalArgument",
        name: "count",
      },
      {
        defaultValue: null,
        kind: "LocalArgument",
        name: "cursor",
      },
      {
        defaultValue: null,
        kind: "LocalArgument",
        name: "filter",
      },
      {
        defaultValue: null,
        kind: "LocalArgument",
        name: "key",
      },
    ],
    kind: "Fragment",
    metadata: {
      connection: [
        {
          count: "count",
          cursor: "cursor",
          direction: "forward",
          path: v0 /*: any*/,
        },
      ],
      refetch: {
        connection: {
          forward: {
            count: "count",
            cursor: "cursor",
          },
          backward: null,
          path: v0 /*: any*/,
        },
        fragmentPathInResult: [],
-        operation: require("./tokenInfoSideBar_MoreNotesQuery.graphql.ts"),
+        operation: tokenInfoSideBar_MoreNotesQuery,
      },
    },
    name: "tokenInfoSideBar_NotesFragment",
    selections: [
      {
        alias: "notes",
        args: [
          {
            kind: "Variable",
            name: "__dynamicKey",
            variableName: "key",
          },
        ],
        concreteType: "NoteConnection",
        kind: "LinkedField",
        name: "__tokenInfoSideBar_notes_connection",
        plural: false,
        selections: [
          {
            alias: null,
            args: null,
            concreteType: "NoteEdge",
            kind: "LinkedField",
            name: "edges",
            plural: true,
            selections: [
              {
                alias: null,
                args: null,
                concreteType: "Note",
                kind: "LinkedField",
                name: "node",
                plural: false,
                selections: [
                  {
                    alias: null,
                    args: null,
                    kind: "ScalarField",
                    name: "id",
                    storageKey: null,
                  },
                  {
                    alias: null,
                    args: null,
                    kind: "ScalarField",
                    name: "documentId",
                    storageKey: null,
                  },
                  {
                    alias: null,
                    args: null,
                    kind: "ScalarField",
                    name: "title",
                    storageKey: null,
                  },
                  {
                    alias: null,
                    args: null,
                    kind: "ScalarField",
                    name: "__typename",
                    storageKey: null,
                  },
                ],
                storageKey: null,
              },
              {
                alias: null,
                args: null,
                kind: "ScalarField",
                name: "cursor",
                storageKey: null,
              },
            ],
            storageKey: null,
          },
          {
            alias: null,
            args: null,
            concreteType: "PageInfo",
            kind: "LinkedField",
            name: "pageInfo",
            plural: false,
            selections: [
              {
                alias: null,
                args: null,
                kind: "ScalarField",
                name: "endCursor",
                storageKey: null,
              },
              {
                alias: null,
                args: null,
                kind: "ScalarField",
                name: "hasNextPage",
                storageKey: null,
              },
            ],
            storageKey: null,
          },
          {
            kind: "ClientExtension",
            selections: [
              {
                alias: null,
                args: null,
                kind: "ScalarField",
                name: "__id",
                storageKey: null,
              },
            ],
          },
        ],
        storageKey: null,
      },
    ],
    type: "Query",
    abstractKey: null,
  };
})();
(node as any).hash = "5e7babc5b768b840540fee0d178b54cd";
export default node;

@n1ru4l
Copy link
Member Author

n1ru4l commented Feb 11, 2021

@sibelius It seems actions don't run for pushes from fork repos

@sibelius
Copy link
Contributor

how can we enable this?
can we remove everything from travis?

I've gave you access to this org and repo

@n1ru4l
Copy link
Member Author

n1ru4l commented Feb 11, 2021

can we remove everything from travis?

I think publishing is automated via travis cc @alloy , we could move it to github actions.

how can we enable this?

I will check later

@alloy
Copy link
Member

alloy commented Feb 12, 2021

Agreed that this should normally go into relay, but I’m not against doing it here temporarily 👍

I assume doing it with regexes is faster than using a babel visitor on the JSON, but it might be nice to compare, if you feel like it (don't feel strong on this at all).

Copy link
Contributor

@sibelius sibelius left a comment

Choose a reason for hiding this comment

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

as this is the same as flow compiler, we can follow this approach

@n1ru4l
Copy link
Member Author

n1ru4l commented Feb 15, 2021

@sibelius The flow compiler does not address this issue. In case you are referring to https://github.com/facebook/relay/pull/2841/files#diff-8258e3677c0534bd73d878b16093be514b2227f8972766d881bf903ff5f0e0d9R15-R27 - that was only a WIP pr that got superseded by facebook/relay#2781 which never addressed this issue (maybe because the @refetchable problematic has been introduced at a later point).

@rubas
Copy link

rubas commented Mar 15, 2021

  • little bump -

Anything that is needed here @n1ru4l to fix this for the moment?

(We use snowpack/webpack pipeline and the current require command even hardcodes the whole filename (foo.graphql.ts) which breaks our pipeline.)

@n1ru4l
Copy link
Member Author

n1ru4l commented Mar 15, 2021

@rubas I want to merge this together with the major release: #275

I have limited time right now and this is not high on my priority list.

For now, you could use patch-package for applying this "fix".

@theseyi
Copy link

theseyi commented Apr 12, 2021

@rubas I want to merge this together with the major release: #275

Since #275 got merged, will there be any progress to merge this as well? @n1ru4l thanks

@n1ru4l
Copy link
Member Author

n1ru4l commented Apr 15, 2021

@theseyi You wanna write some tests for this?

* Update CHANGELOG.md [skip ci]

* Bump version to: 13.0.3 [skip ci]

* chore: bump typescript from 4.1.4 to 4.1.5 (relay-tools#268)

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.1.4 to 4.1.5.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](microsoft/TypeScript@v4.1.4...v4.1.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Update CHANGELOG.md [skip ci]

* Bump version to: 13.0.4 [skip ci]

* chore: bump @types/node from 14.14.25 to 14.14.28

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.25 to 14.14.28.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* fix: revert breaking changes introduced in 13.0.3 (relay-tools#274)

* Revert "refactor: use factory functions instead of deprecated functions"

This reverts commit 812d17e.

* Revert "refactor: remove deprecated typescript function calls in favor of the factory; replace @ts-ignores with proper code (microsoft/TypeScript#40263 (comment))"

This reverts commit 55c58be.

* Revert "refactor: some of the statements are redundant. It is not necessary to write to write only properties."

This reverts commit 2cbd1de.

* Revert "refactor: address all the typescript deprecations by using the factory"

This reverts commit 72e0b4a.

* chore: run CI github action on pull request

* fix: typo

* Update CHANGELOG.md [skip ci]

* Bump version to: 13.0.5 [skip ci]

* Update CHANGELOG.md [skip ci]

* Bump version to: 13.0.6 [skip ci]

* feat: include .d.ts types in release (relay-tools#309)

* feat: drop typescript 3 and Node.js 10 support (relay-tools#275)

* refactor: address all the typescript deprecations by using the factory

* refactor: some of the statements are redundant. It is not necessary to write to write only properties.

* refactor: remove deprecated typescript function calls in favor of the factory; replace @ts-ignores with proper code (microsoft/TypeScript#40263 (comment))

* refactor: use factory functions instead of deprecated functions

* feat: bump peerDependencies version

* dps: upgrade to latest typescript version

* chore: replace rm with rimraf for cross platform support

* chore: replace fixture tests with inline snapshot tests

* docs: add notice about minimum TypeScript version.

* chore: drop node 10 support

* Update CHANGELOG.md [skip ci]

* Bump version to: 13.0.7 [skip ci]

* Update CHANGELOG.md [skip ci]

* Bump version to: 13.0.8 [skip ci]

* feat: replace require calls by static (top level) or dynamic imports based on ts compiler options

* feat: add tests for require call replacement logic

* chore: add comment

* fix: parse contents of tsconfig file into compiler options

Converts strings to enum values etc.

* fix: remove support for dynamic imports

* fix: import default

Co-authored-by: Eloy Durn <eloy.de.enige@gmail.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
Co-authored-by: Sibelius Seraphini <sibeliusseraphini@gmail.com>
Co-authored-by: Tim Griesser <tgriesser10@gmail.com>
Co-authored-by: Erik Müller <e.mueller@detelling.com>
@n1ru4l n1ru4l marked this pull request as ready for review July 21, 2021 08:12
@n1ru4l
Copy link
Member Author

n1ru4l commented Jul 21, 2021

@asterikx Do you mind-altering the README to include a section on how to properly configure typescript and relay config in order to produce esm imports? After that is done I will merge this! Thank you so much for adding the tests

@n1ru4l n1ru4l added the Version: Minor Increment the minor version when merged label Aug 2, 2021
@n1ru4l n1ru4l merged commit fde5992 into relay-tools:master Aug 2, 2021
@n1ru4l n1ru4l mentioned this pull request Aug 2, 2021
@github-actions
Copy link

github-actions bot commented Aug 8, 2021

🚀 PR was released in v14.1.0 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
released Version: Minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants