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

Global fragment registry #1209

Merged
merged 41 commits into from Mar 14, 2024
Merged

Global fragment registry #1209

merged 41 commits into from Mar 14, 2024

Conversation

Quramy
Copy link
Owner

@Quramy Quramy commented Mar 5, 2024

What

Currently ts-graphql-plugin only can analyze template expression interpolated into template span.

/* fragments.tsx */

export const userFragment = gql`
  fragment UserFragment on User {
    id
    name
  }
`;
/* App.tsx */
import { userFragment } from "./fragments";

const query = gql`
  ${userFragment}
  query AppQuery {
    viewer {
      ...UserFragment
    }
  }
`;

This PR introduces global fragment registration. The global fragment registration allows to analyze sources without referring using template span.

/* fragments.tsx */

const userFragment = gql`
  fragment UserFragment on User {
    id
    name
  }
`;
/* App.tsx */

const query = gql`
  query AppQuery {
    viewer {
      ...UserFragment
    }
  }
`;

Related: #360

Tasks

  • Config
    • Add bool field to enable global fragments
    • Add field to exclude specified files for fragment search
  • Language Services
    • getCompletionsAtPosition
    • getSemanticDiagnostics
      • Add synthetic diagnostics for fragment name uniqueness
    • getQuickInfoAtPosition -> Not affected
  • CLI
    • typegen
    • extract
    • validate
    • report
  • Modify document
  • Add e2e specs

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 96.97543% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 96.54%. Comparing base (120b4b8) to head (cc282de).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1209      +/-   ##
==========================================
- Coverage   96.55%   96.54%   -0.01%     
==========================================
  Files          66       72       +6     
  Lines        4702     5615     +913     
  Branches      900      829      -71     
==========================================
+ Hits         4540     5421     +881     
- Misses        159      192      +33     
+ Partials        3        2       -1     
Files Coverage Δ
src/analyzer/analyzer.ts 97.17% <100.00%> (+0.79%) ⬆️
src/analyzer/extractor.ts 96.80% <100.00%> (+0.98%) ⬆️
src/analyzer/index.ts 100.00% <100.00%> (ø)
src/analyzer/type-generator.ts 98.33% <100.00%> (+0.02%) ⬆️
src/cache/index.ts 100.00% <100.00%> (ø)
src/cache/lru-cache.ts 100.00% <100.00%> (ø)
src/errors/index.ts 100.00% <100.00%> (ø)
src/gql-ast-util/index.ts 100.00% <100.00%> (ø)
src/gql-ast-util/utility-functions.ts 100.00% <100.00%> (ø)
...uage-service-adapter/get-completion-at-position.ts 96.77% <100.00%> (+0.41%) ⬆️
... and 18 more

... and 1 file with indirect coverage changes

@Quramy Quramy marked this pull request as ready for review March 13, 2024 13:41
@Quramy Quramy merged commit d9e704c into main Mar 14, 2024
3 checks passed
@Quramy Quramy deleted the fragment_registry branch March 14, 2024 21:51
ckomop0x pushed a commit to ckomop0x/ckomop0x.me.site.v2 that referenced this pull request Mar 20, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ts-graphql-plugin](https://togithub.com/Quramy/ts-graphql-plugin) |
[`3.0.2` ->
`3.1.2`](https://renovatebot.com/diffs/npm/ts-graphql-plugin/3.0.2/3.1.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/ts-graphql-plugin/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/ts-graphql-plugin/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/ts-graphql-plugin/3.0.2/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/ts-graphql-plugin/3.0.2/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>Quramy/ts-graphql-plugin (ts-graphql-plugin)</summary>

###
[`v3.1.2`](https://togithub.com/Quramy/ts-graphql-plugin/releases/tag/v3.1.2)

[Compare
Source](https://togithub.com/Quramy/ts-graphql-plugin/compare/v3.1.1...v3.1.2)

#### What's Changed

- fix: Add arguments length check by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1240

**Full Changelog**:
Quramy/ts-graphql-plugin@v3.1.1...v3.1.2

###
[`v3.1.1`](https://togithub.com/Quramy/ts-graphql-plugin/releases/tag/v3.1.1)

[Compare
Source](https://togithub.com/Quramy/ts-graphql-plugin/compare/v3.1.0...v3.1.1)

#### What's Changed

- fix: Add addons js to npm files entries by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1238

**Full Changelog**:
Quramy/ts-graphql-plugin@v3.1.0...v3.1.1

###
[`v3.1.0`](https://togithub.com/Quramy/ts-graphql-plugin/releases/tag/v3.1.0)

[Compare
Source](https://togithub.com/Quramy/ts-graphql-plugin/compare/v3.0.2...v3.1.0)

#### New Features

##### 🎉 ts-graphql-plugin gets compat `graphql-codegen` 🎉

- The new `enabledGlobalFragments` option allows to analyze operation
and fragments defined in different templates without interpolation(e.g.
`${postFragment}`).
- Function call expression is available as GraphQL document via `tag`
option .

In combination these, ts-graplql-plugin works with `graphql-codegen`
compatible code such as:

```tsx
import { graphql } from "./gql";

const postFragment = graphql(`
  fragment PostFragment on Post {
    title
    author {
      name
    }
  }
`);

const query = graphql(`
  query AppQuery {
    popularPosts {
      id
      ...PostFragment
    }
  }
`);
```

See
[example](https://togithub.com/Quramy/ts-graphql-plugin/tree/main/project-fixtures/graphql-codegen-prj)
If you want more details,

#### What's Changed

- chore: Modify Codecov configuration by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1204
- chore: Modify jest instrumentation by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1205
- chore: Allow findAllNodes callback to return generic AST nodes by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1220
- Global fragment registry by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1209
- chore: Organize package.json by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1225
- feat: Add `tag` customize pattern by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1226
- chore: Update example report md by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1227
- modify prettier config by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1228
- docs: Add example using graphql-codegen by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1229
- docs: Write about `enabledGlobalFragments` by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1232
- fix: Transformer should uses getFragmentDependenciesForAST by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1233
- feat: Resolve interpolation referring call expression by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1234
- fix: Allow to transform CallExpression by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1235
- chore: Fix module name typo by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1237
- fix: TypedDocument addon import specifier by
[@&#8203;Quramy](https://togithub.com/Quramy) in
[Quramy/ts-graphql-plugin#1236

#### **Full Changelog**:
Quramy/ts-graphql-plugin@v3.0.2...v3.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ckomop0x/ckomop0x.me.site.v2).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNDUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI2MS4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

1 participant