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
with a pre hook.
In each module, a new folder named _gen
with resolvers.ts
and typedefs.ts
containing everything needed for 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: {
'*': {
'*': []
}
}
});
Now, enjoy! 🔥
Enums 0/ Creates a dedicated module for all Enums with *.graphql
and List*.ts
to get valid graphql types & ready to use list in the UI.
Merge 1/ Generate your resolvers.ts
and typedefs.ts
files per module
Merge 2/ Generate global _ctxModules.ts
(merge all _ctxXXX.ts
of each modules)
Merge 3/ Generate global _appModules.ts
(merge all index.ts
of each modules)
Merge 4/ Generate global _urqlCache.ts
(merge all _urqlCacheXXX.ts
of each modules)
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.