Repository navigation
fix: plugin bugs found while documenting - #18
Merged
Merged
Conversation
The Requester type refers to DocumentNode, but the base visitor only imports it for the documentNode modes. Import it for graphQLTag and external as well, respecting documentNodeImport and useTypeImports.
documentMode string referenced a TypedDocumentString class that was never defined. Emit the class (as typed-document-node and the client preset do, without the @graphql-typed-document-node/core dependency), type the operation documents with their result and variables, and pass the TypedDocumentString to the requester.
Replace the dummy test with snapshots of the generated output for every documentMode, and compile the output of typescript-operations plus this plugin, together with a k6 script using the SDK, with tsc.
… setup typescript-operations v6 generates the enum and input types itself, so combining it with the typescript plugin duplicates those declarations; this plugin does not emit schema types. Document to use typescript-operations on its own, and document documentMode string.
Every request embedded the complete source document (all operations and fragments in it), followed by the used fragments, so fragments defined in the same document were included twice. Emit only the operation itself followed by the fragments it transitively uses, each once.
prettier was used at runtime but only a devDependency, so it was bundled into dist (5.0 MB index.js plus a 7.5 MB source map). The request body is now printed with graphql's print, which already formats the operation and fragments, so prettier is no longer needed. dist/index.js is now about 7 kB.
Subscriptions were written to the mutations/ folder.
clean: true emptied the whole output directory, which removed bruno.json and environments when the output pointed to the collection root. Only remove the .bru files (except folder.bru) in the queries/, mutations/ and subscriptions/ folders the plugin writes to, and those folders when they are empty afterwards.
Add the url and auth options, defaulting to the previously hardcoded
{{graphql-gateway}}/graphql and none. Make all options optional and
export the BrunoPluginConfig type.
Test the generated requests of several operations per document (fragments from other documents, subscriptions), the url, auth, headers and defaults options, and that clean only removes generated requests. Write the output to a temporary directory instead of the tracked src/__output__.
The output prefixed the whole printed schema with 'extend', which only worked when it started with a schema definition without description. A schema without root types resulted in 'extend type ...' or 'extend directive ...', and a schema description in invalid syntax. Convert just the schema definition to a schema extension (dropping its description, which extensions cannot have). Plain schemas keep working: graphql's buildSchema and makeExecutableSchema accept 'extend schema' without a schema definition.
Set extendSchema: false to print a plain schema definition (including its description) instead of 'extend schema'. Defaults to true, the previous behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the bugs found while documenting the plugins in #17 (merged), and updates the README "notes and limitations" sections accordingly. One commit per fix.
k6
graphQLTag(default) /external: missingDocumentNodeimport — theRequestertype usedDocumentNodewithout importing it. The visitor now adds the import (fromdocumentNodeImport, respectinguseTypeImports) for every mode exceptstring.documentMode: "string": undefinedTypedDocumentString— the class is now emitted in the output, the same classtyped-document-node/ the client preset generate (aStringsubclass), without the dependency on@graphql-typed-document-node/core(__apiTypeis structurally compatible withDocumentTypeDecoration). Operation documents are cast toTypedDocumentString<Result, Variables>and the requester getsdoc: TypedDocumentString<R, V>. Checked that the class serializes to the query string withJSON.stringifyin k6 itself (k6 v2.3).typescript+typescript-operationsv6 — not caused by this plugin:typescript-operationsv6 generates the enum and input types itself, so they clash with thetypescriptplugin's. The k6 plugin only emits documents and the SDK (now asserted in a test). The README documents to usetypescript-operationson its own.documentMode, and a type check that compiles thetypescript-operations+ k6 output together with a k6 script using the SDK (with@ts-expect-errorcases for missing variables / bad enum values) withtsc. New devDependencies:@graphql-codegen/typescript-operations,@types/k6,@types/node,graphql-tag.bruno
graphql'sprint.clean: trueemptied the output directory — now only removes the.brufiles (exceptfolder.bru) inqueries/,mutations/andsubscriptions/and those folders when empty.bruno.json,collection.bru, environments and other files are never touched. Tested.mutations/— now written tosubscriptions/.urlandauthoptions, defaulting to{{graphql-gateway}}/graphqlandnone.printit is no longer needed, so it is dropped entirely.dist/index.js: 5.0 MB (+ 7.5 MB source map) → 6.9 kB.src/__output__(removed).typedefs
extend schema: intended (it works with plain schemas:graphql'sbuildSchemaandmakeExecutableSchemaacceptextend schemawithout a schema definition, and it merges with other type defs), but the implementation prefixed the whole printed schema withextend. That broke schemas without root types (extend type A ...,extend directive ...) and schemas with a description (invalid syntax). Now only the schema definition is converted to a schema extension (description dropped, extensions cannot have one).extendSchemaoption (defaulttrue) to print a plainschema { ... }instead.buildSchema.Changesets
subscriptions/folder,cleansemantics, no comments in body); noted in the changeset.extend \tschema {→\textend schema {).pnpm check,pnpm build(incl. publint) andpnpm test:cipass locally.