-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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: add support for metadata and persisted operations in client preset #8757
Conversation
🦋 Changeset detectedLatest commit: 7633dfa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
🚀 Snapshot Release (
|
Package | Version | Info |
---|---|---|
@graphql-cli/codegen |
2.4.25-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/cli |
2.16.5-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/visitor-plugin-common |
2.13.8-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-document-nodes |
2.3.13-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/gql-tag-operations |
1.6.2-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-operations |
2.5.13-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-resolvers |
2.7.13-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typed-document-node |
2.3.13-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript |
2.8.8-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/client-preset |
1.3.0-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/graphql-modules-preset |
2.5.12-alpha-20230118075831-1d93c9826 |
npm ↗︎ unpkg ↗︎ |
🚀 Website PreviewThe latest changes to the website are available as preview in: https://30ddff48.graphql-code-generator.pages.dev |
@n1ru4l I've spent the last few days trying to figure out how to get persisted queries working with codegen, myself, and I stumbled across this PR. One thing isn't clear to me: does this actually transform the client code for production builds? I don't use Apollo or Urql (I'm stubborn, but weakening), so all I really want to see is for this kind of transformation to happen... from (dev):
to (prod):
Hope that makes some sense. Please let me know what you think. |
b8972ae
to
7d84b09
Compare
@shmax Yes, this is possible 🎉 graphql-code-generator/packages/presets/client/tests/client-preset.spec.ts Lines 1230 to 1232 in edb9a80
|
Ah, very cool. Okay, so that's the |
@shmax The graphql function returns the document node that has the hash included 😎 |
Sure, I understand that, but in my project I type queries right into the source, eg: // someclientfile.ts
const ProductDetails: FC<ProductDetailsProps> = (_props) => {
const { data } = useQuery(["sku"], async () =>
graphqlAsync(
graphql(/* GraphQL */ `
query productDetailsPage($skuId: ID, $loadMod: Boolean) {
sku(id: $skuId, loadMod: $loadMod) {
id
fullName
}
}
`),
{
skuId: (9).toString(),
}
)
);
...
} That's the whole point of this package, isn't it? So you can generate typings for the response document? Do you have some alternate approach that hasn't occurred to me? |
packages/presets/client/src/index.ts
Outdated
plugin: async () => { | ||
await tdnFinished.promise; | ||
return { | ||
content: JSON.stringify(Object.fromEntries(persistedOperations.entries()), null, 2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use fast json here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is fast json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5b53828
to
cef8337
Compare
packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts
Outdated
Show resolved
Hide resolved
packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts
Outdated
Show resolved
Hide resolved
d5f618c
to
a9062d9
Compare
unstable_onDocumentNode?: Unstable_OnDocumentNode; | ||
unstable_omitDefinitions?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added them as unstable as I don't want anyone outside the client preset to use these features tbh.
8f4f163
to
03e64aa
Compare
1de4db4
to
95efaf7
Compare
5552d9b
to
36baf2e
Compare
diff --git a/website/algolia-lockfile.json b/website/algolia-lockfile.json%0Aindex 104e2f2cf..3cbb7cbab 100644%0A--- a/website/algolia-lockfile.json%0A+++ b/website/algolia-lockfile.json%0A@@ -880,7 +880,7 @@%0A "anchor": "appendix-ii-compatibility"%0A }%0A ],%0A- "content": "066e74d7d5984a87318ec6661c2ffb3b",%0A+ "content": "93a7f1749a22be8fad86f9bdceee42d6",%0A "url": "https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue",%0A "domain": "https://www.the-guild.dev/graphql/codegen/",%0A "hierarchy": [ |
8717b93
to
492825d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can wait for @graphql-tools/documents
to publish then merge this?
df4d080
to
d053e8c
Compare
/theguild newsletter |
@n1ru4l hey there, I've had a chance to tinker with this awesome feature a bit, and I have some feedback for you. Invalid AST?When export const UpdateWishlistMutationDocument = {
__meta__: { hash: "c3cc8d68aaaa31edda041890c6444d412ab72208" },
kind: "Document",
definitions: [ Interesting, but this AST structure doesn't validate. The library I use (graphql-php) throws an exception here ("Node is missing kind"). Behavior of
|
Closes #8756
Closes #8822
This implementation is very ugly IMHO, but I could not see a different way in how things are structured right now. 🥲