
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@nerd-coder/graphql-codegen-svelte-queries
Advanced tools
Codegen plugins to generate fully typed queries for Svelte with Apollo and Urql
GraphQL Code Generator plugin to use Apollo or Urql in Svelte with full Typescript support
Inspired by ticruz38's work. Since ticruz38 didn't seem to update his repo anymore, I decieded to continue his work by creating this repo. And also added support for Urql queries.
graphql-codegen-svelte-apollo
is a plugin for graphql-code-generator ecosystem, please refer to their website for documentation relative to the configuration in codegen.yml
Ensure that your project contains all needed dependencies for this plugin
npm i -S graphql
npm i -D @graphql-codegen/cli
npm i -D @graphql-codegen/typescript
npm i -D @graphql-codegen/typescript-operations
npm i -D @nerd-coder/graphql-codegen-svelte-queries
clientPath
string
Path to the apollo or urql client for this project (should point to a file with an the client as default export)
generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- graphql-codegen-svelte-apollo
config:
clientPath: PATH_TO_APOLLO_CLIENT
clientType: apollo
clientType
'apollo' | 'urql'
Client type to generate
generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- graphql-codegen-svelte-apollo
config:
clientPath: PATH_TO_APOLLO_CLIENT
clientType: apollo
asyncQuery
boolean
false
By default, the plugin only generate observable queries, sometimes it may be useful to generate promise-based queries
generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- @nerd-coder/graphql-codegen-svelte-queries
config:
clientPath: PATH_TO_APOLLO_CLIENT
clientType: apollo
asyncQuery: true
importFrom
string
''
When provided, import types from the generated typescript types file path. if not given, omit import statement.
I you're not using this config, it's recommended to also specify those additional config options for lean code generation:
noExport: true
onlyOperationTypes: true
(Those config abolve are belong to TypeScriptDocumentsPluginConfig
type in @graphql-codegen/typescript-operations
package)
For the given input:
fragment TransactionFragment on TransactionDescription {
contractAddress
from
gasUsed
gasPrice
input
isError
to
value
}
query Transactions($address: String) {
transactions(address: $address) {
...TransactionFragment
}
}
And the following configuration:
schema: YOUR_SCHEMA_HERE
documents: './src/**/*.graphql'
generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- @nerd-coder/graphql-codegen-svelte-queries
config:
clientPath: PATH_TO_APOLLO_CLIENT
clientType: apollo
Codegen will pre-compile the GraphQL operation into a DocumentNode
object, and generate a ready-to-use Apollo query for each operation you have.
In you application code, you can import it from the generated file, and use the query in your component code:
<script lang="ts">
import { Transactions } from 'codegen'
var address = '0x0000000000000000000000000000'
$: ({ rawData, loading, errorMessages } = Transactions({ address }))
</script>
{#if $loading}
<p>Loading ...</p>
{:else if $errorMessages.length}
<p>{$errorMessages.join()}</p>
{:else}
<ul>
{#each $rawData || [] as transaction}
<li>Sent transaction from {transaction.from} to {transaction.to}</li>
{:else}
<li>No data available!</li>
{/each}
</ul>
{/if}
Each time you change the address, the query will re-fetch and show the new results in the template.
Sometimes, you may need/prefer to have an async query (only available with asyncQuery option set to true)
For the given input:
fragment TransactionFragment on TransactionDescription {
contractAddress
from
gasUsed
gasPrice
input
isError
to
value
}
query Transactions($address: String) {
transactions(address: $address) {
...TransactionFragment
}
}
And the following configuration:
schema: YOUR_SCHEMA_HERE
documents: './src/**/*.graphql'
generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- graphql-codegen-svelte-apollo
config:
clientPath: PATH_TO_APOLLO_CLIENT
clientType: apollo
asyncQuery: true
Codegen will pre-compile the GraphQL operation into a DocumentNode
object, and generate a ready-to-use Apollo query for each operation you have.
In you application code, you can import it from the generated file, and use the query in your component code:
<script lang="ts">
import { AsyncTransactions } from 'codegen'
var address = '0x0000000000000000000000000000'
</script>
<ul>
{#await AsyncTransactions({ address })} Loading... {:then transactions} {#each transactions || []
as transaction}
<li>Sent transaction from {transaction.from} to {transaction.to}</li>
{/each} {/await}
</ul>
FAQs
Codegen plugins to generate fully typed queries for Svelte with Apollo and Urql
The npm package @nerd-coder/graphql-codegen-svelte-queries receives a total of 2 weekly downloads. As such, @nerd-coder/graphql-codegen-svelte-queries popularity was classified as not popular.
We found that @nerd-coder/graphql-codegen-svelte-queries demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.