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

major(core/graphcache): Remove graphql imports by default #3097

Merged
merged 14 commits into from
Mar 24, 2023
Merged

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 24, 2023

Resolves #3096

Summary

This removes graphql from peerDependencies on all packages. @urql/core and @urql/exchange-graphcache will now depend on @0no-co/graphql.web instead and switch to graphql types dynamically where needed, and otherwise either accept @0no-co/graphql.web’s types (which will also switch to graphql; See: 0no-co/graphql.web#10) or the native graphql types.

This effectively replaces all imports we use from graphql with smaller alternatives from @0no-co/graphql.web by default as per the RFC at #3096.

Set of changes

  • Replace graphql with @0no-co/graphql.web
  • Add types shim for common imports to @urql/core which is marked with the /*!@ts-ignore*/ pragma in the type output
  • Replace formatDocument in @urql/core with an implementation that avoids using visit
  • Remove graphql from peerDependencies in all packages
  • Replace graphql usage in @urql/exchange-graphcache and add shim types for schema

@kitten kitten changed the title Feat/graphql web major(core/graphcache): Remove graphql imports by default Mar 24, 2023
Comment on lines +41 to +43
return code
.replace(emptyImportRe, '')
.replace(gqlImportRe, x => '/*!@ts-ignore*/\n' + x);
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: This build change marks graphql imports in out d.ts typings files with a /*!@ts-ignore*/ pragma. While imports from graphql will change to any when the package isn’t installed, we still need to mark this in case a user has skipLibCheck: false set in their tsconfig

export type DocumentInput<
Result = { [key: string]: any },
Variables = { [key: string]: any }
> = string | DocumentNode | TypedDocumentNode<Result, Variables>;
Copy link
Member Author

@kitten kitten Mar 24, 2023

Choose a reason for hiding this comment

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

NOTE: This new type determines what we accept for query language inputs. However, TypedDocumentNode<any, any> will also work instead of DocumentNode in packages that depend on @urql/core. Alternatively, even Exclude<DocumentInput<T, V>, string> works

@kitten kitten merged commit f182601 into main Mar 24, 2023
@kitten kitten deleted the feat/graphql-web branch March 24, 2023 13:15
This was referenced Mar 24, 2023
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.

RFC: Reduce size of shipped GraphQL.js code by default
2 participants