Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
graphql-codegen-compiler
Advanced tools
graphql-codegen-compiler
This package compiles the output of graphql-codegen-core
along with GeneratorConfig
and Settings
, and compiles the template, returns an array of FileOutput
.
The main entry point of the package is compile
method, and you can import it directly and use it without the CLI package.
We are using Handlebars as template compiler, with some custom Handlebars helpers that helps to generate GraphQL related code easily.
toPrimitive(type: string)
Accepts a string with a GraphQL type and converts it to the language primitive as specified in the template config, if the type isn't a primitive - it just returns it.
Example:
type MyType {
f1: String
}
{{#each types}}
Type {{ name }} fields:
{{#each fields}}
Field {{ name }} type is: {{ toPrimitive type }}
{{/each}}
{{/each}}
Output:
Type MyType fields:
Field f1 type is: string
ifDirective(context: any, directiveName: string)
Special GraphQL helper that accepts any GraphQL entity, and extracts the GraphQL Directives of the entity.
The compiled context is the arguments values of the entity.
Example:
type MyType @addName(name: "Dotan") {
f1: String
}
directive @addName(name: String!) on OBJECT
{{#each types}}
Type name: {{ name }}
Extra name? {{#ifDirective this "appName"}}Yes! and the name is: {{ name }}{{/ifDirective}}
{{/each}}
Output:
Type name: MyType
Extra name? Yes! and the name is: Dotan
unlessDirective(context: any, directiveName: string)
The opposite of ifDirective
.
Example:
type MyType {
f1: String
}
directive @addName(name: String!) on OBJECT
{{#each types}}
Type name: {{ name }}
Extra name? {{#unlessDirective this "appName"}}No!{{/unlessDirective}}
{{/each}}
Output:
Type name: MyType
Extra name? No!
toComment(str: string)
Prints a string as comment with /* ... */
, and also trims multiple lines into a single line.
Useful for description
field of GraphQL entities.
Example:
{{toComment "hi"}}
Output:
/* hi */
eachImport(element: any)
Iterates over a calculated array of imports (file names) that in use by the element
.
Example:
{{#eachImport type}}
import { {{ name }} } from './{{file}}';
{{/eachImport}}
times(count: number)
Returns the template child string count
times, the execution context of the child content is the i/times.
Example:
{{#times 3}}
Hello {{ this }}!
{{/times}}
Output:
Hello 0
Hello 1
Hello 2
for(from: number, to: number, incr: number)
Similar to for
loop.
Returns the template child string amount of times according to from
to to
by increasing incr
, the execution context of the child content is the i/times.
Example:
{{#for 3 6 1}}
Hello {{ this }}!
{{/times}}
Output:
Hello 3
Hello 4
Hello 5
limitedEach(from: number, to: number, incr: number)
Similar to for
loop.
Returns the template child string amount of times according to from
to to
by increasing incr
, the execution context of the child content is the i/times.
Example:
{{#for 3 6 1}}
Hello {{ this }}!
{{/times}}
Output:
Hello 3
Hello 4
Hello 5
toLowerCase(str: string)
Return a lowercase version of the string.
Example:
{{toLowerCase "Hello" }}
Output:
hello
toUpperCase(str: string)
Return an uppercase version of the string.
Example:
{{toUpperCase "Hello" }}
Output:
HELLO
toSnakeCase(str: string)
Return an snake case version of the string.
Example:
{{toSnakeCase "doSomething" }}
Output:
do-something
toTitleCase(str: string)
Return an title case version of the string.
Example:
{{toTitleCase "doSomething" }}
Output:
Do Something
toCamelCase(str: string)
Return an camel case version of the string.
Example:
{{toCamelCase "DoSomething" }}
Output:
doSomething
multilineString(str: string)
Converts a multiline string into a string with line breaks, to prevent code from being broken.
Example:
{{toCamelCase "myString
other line" }}
Output:
"myString" +
"other line"
FAQs
GraphQL code generator compiler
The npm package graphql-codegen-compiler receives a total of 2,442 weekly downloads. As such, graphql-codegen-compiler popularity was classified as popular.
We found that graphql-codegen-compiler 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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.