
Security News
OpenGrep Restores Fingerprinting in JSON and SARIF Outputs
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
graphql-directive-resolve-as
Advanced tools
Graphql directive to resolve fields as different prop names of the belonging object
Supply Chain Security
Vulnerability
Quality
Maintenance
License
Graphql directive to resolve fields as different prop names of the belonging object.
This directive helps you not to declare resolvers over and over just because the name you want to expose is different to the prop name.
It allows resolution for nested objects, converting a string in dot notation into an object reference.
yarn add graphql-directive-resolve-as
or
npm i graphql-directive-resolve-as
const { resolveAs } = require('graphql-directive-resolve-as');
const schema = makeExecutableSchema({
typeDefs,
resolvers,
schemaDirectives: {
resolveAs,
...
},
});
then you can use it in your fields like this:
const typeDefs = `
type User {
name: String @resolve_as(name: "firstName")
lastName: String,
city: String @resolveAs(name: "country.city.name")
firstFriend: String @resolveAs(name: "friends.0.name")
}
type Query {
me: User
}
`;
me
query resolver could be something like this:
const resolvers = {
Query: {
me: () => ({
firstName: 'John',
lastName: 'Doe',
friends: [
{
name: 'Edu'
},
{
name: 'Natalia'
}
],
country: {
name:'Germany',
city: {
name:'Berlin',
neighborhood: {
name: "Kreuzberg"
}
}
}
}),
},
};
if you use
graphql-import
then you need to add this definition on top of the schema:
directive @resolveAs(name: String) on FIELD_DEFINITION
name
= Path as string in dot notation to the object property to be resolved.
FAQs
Graphql directive to resolve fields as different prop names of the belonging object
We found that graphql-directive-resolve-as 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
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.