Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
mercurius-codegen
Advanced tools
[![npm version](https://badge.fury.io/js/mercurius-codegen.svg)](https://badge.fury.io/js/mercurius-codegen)
Get full type-safety and autocompletion for mercurius with TypeScript using GraphQL Code Generator seamlessly while you code.
pnpm add mercurius-codegen
# or
yarn add mercurius-codegen
# or
npm install mercurius-codegen
// src/index.ts
import Fastify from 'fastify'
import mercurius from 'mercurius'
import mercuriusCodegen from 'mercurius-codegen'
const app = Fastify()
app.register(mercurius, {
schema: `
type Query {
hello(greetings: String!): String!
}
`,
resolvers: {
Query: {
hello(_root, { greetings }) {
// greetings ~ string
return 'Hello World'
},
},
},
})
mercuriusCodegen(app, {
targetPath: './src/generated/graphql.ts',
})
// Then it will automatically generate the file,
// and without doing anything special,
// the resolvers are going to be typed,
// or if your resolvers are in different files...
app.listen(8000)
import { IResolvers } from 'mercurius'
// Fully typed!
export const resolvers: IResolvers = {
Query: {
hello(_root, { greetings }) {
// greetings ~ string
return 'Hello World'
},
},
}
By default it disables itself if NODE_ENV is 'production'
It automatically uses prettier resolving the most nearby config for you
There are a couple extra options to be specified
interface CodegenMercuriusOptions {
/**
* Specify the target path of the code generation.
*
* Relative to the directory of the executed script if targetPath isn't absolute
* @example './src/generated/graphql.ts'
*/
targetPath: string
/**
* Disable the code generation manully, by default it's `process.env.NODE_ENV === 'production'`
*/
disable?: boolean
/**
* Don't notify to the console
*/
silent?: boolean
/**
* Specify GraphQL Code Generator configuration
* @example
* ```js
* codegenConfig: {
* scalars: {
* DateTime: "Date",
* }
* }
* ```
*/
codegenConfig?: CodegenPluginsConfig
/**
* Add code in the beginning of the generated code
*/
preImportCode?: string
}
mercuriusCodegen(app, {
targetPath: './src/generated/graphql.ts',
disable: false,
silent: true,
codegenConfig: {
scalars: {
DateTime: 'Date',
},
},
preImportCode: `
// Here you can put any code and it will be added at very beginning of the file
`,
})
MIT
FAQs
[![npm version](https://badge.fury.io/js/mercurius-codegen.svg)](https://badge.fury.io/js/mercurius-codegen)
The npm package mercurius-codegen receives a total of 2,286 weekly downloads. As such, mercurius-codegen popularity was classified as popular.
We found that mercurius-codegen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.