Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
graphql-codegen-modules-gen
Advanced tools
To use Graphql-Modules well, you need to organize your code by modules (that's the all point 😉).
Something like:
...
├── modules
│ │
│ ├── user
│ │ └── graphql <-- client graphql operations
│ │ │ └── FRAG.user.gql
│ │ │ └── MUTATION.CreateUser.gql
│ │ │ └── QUERY.GetUser.gql
│ │ │ └── QUERY.GetUsers.gql
│ │ └── resolvers <-- server graphql resolvers
│ │ │ └── _Mutation.ts
│ │ │ └── _Query.ts
│ │ │ └── User.ts
│ │ └── typedefs <-- server graphql type definitions
│ │ │ └── _Mutation.graphql
│ │ │ └── _Query.graphql
│ │ │ └── TYPE.User.graphql
│ │ └── index.ts <-- server module creation / orchestration
│ │
│ ├── module2
│ │ └── graphql
│ │ │ └── ...
│ │ └── resolvers
│ │ │ └── ...
│ │ └── typedefs
│ │ │ └── ...
│ │ └── index.ts
│ │
│ ├── module3
│ │ └── ...
...
In index.ts
of each module, you will bring all your resolvers and type definitions together. To do this, you can use GraphQL Tools - Merging resolvers and the merge will be done at runtime. Unfortunately, it will not work well with bundlers (check this)
That's why graphql-codegen-modules-gen
exist. The cli, will generate you resolvers.ts
and typedefs.ts
per module at build time. Then, you will compose your index.ts
with these files.
yarn add graphql-codegen-modules-gen -D
package.json
"gen-mg": "yarn graphql-codegen-modules-gen ./src/lib/modules",
replacing ./src/lib/modules
by the location of your modules
yarn gen-mg
At the end of your codegen.yml
file, add:
hooks:
afterAllFileWrite:
- yarn gen-mg
A new folder named _gen
with resolvers.ts
and typedefs.ts
containing everything needed in your index.ts
file.
...
├── modules
│ │
│ ├── user
│ │ └── _gen <-- ✨ new folder (I put it in the .gitignore)
│ │ │ └── resolvers.ts <-- ✨ new file, combine resolvers, export resolvers
│ │ │ └── typedefs.ts <-- ✨ new file, merged typedefs, export typedefs
│ │ └── graphql
│ │ │ └── FRAG.user.gql
│ │ │ └── MUTATION.CreateUser.gql
│ │ │ └── QUERY.GetUser.gql
│ │ │ └── QUERY.GetUsers.gql
│ │ └── resolvers
│ │ │ └── _Mutation.ts
│ │ │ └── _Query.ts
│ │ │ └── User.ts
│ │ └── typedefs
│ │ │ └── _Mutation.graphql
│ │ │ └── _Query.graphql
│ │ │ └── TYPE.User.graphql
│ │ └── index.ts
│ │
│ ├── module2
│ │ └── graphql
│ │ │ └── ...
│ │ └── resolvers
│ │ │ └── ...
│ │ └── typedefs
│ │ │ └── ...
│ │ └── index.ts
│ │
│ ├── module3
│ │ └── ...
...
And here is how my index.ts
file looks like:
import { createModule } from 'graphql-modules';
import { resolvers } from './_gen/resolvers';
import { typeDefs } from './_gen/typedefs';
export const userModule = createModule({
id: 'user-module',
typeDefs,
resolvers,
providers: [],
middlewares: {
'*': {
'*': []
}
}
});
FAQs
## 💡 Motivation
We found that graphql-codegen-modules-gen 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.