Socket
Book a DemoInstallSign in
Socket

graphql-directive-computed-property

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-directive-computed-property

GraphQL directive for create computed property

0.1.1
latest
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

graphql-directive-computed-property

Version downloads PRs Welcome MIT License

Introduction

The directive allows creating a computed property from fields where is defined.

Table of Contents

Installation

yarn add graphql-directive-computed-property

This package requires graphql and graphql-tools as peer dependency

Usage

const { makeExecutableSchema } = require('graphql-tools');
const computedDirective = require('graphql-directive-computed-property');

const typeDefs = `
  type User {
    firstName: String
    lastName: String
    fullName: String @computed(value: "$firstName $lastName")
  }

  type Query {
    me: User
  }
`;

const resolvers = {
  Query: {
    me: () => ({
      firstName: 'John',
      lastName: 'Doe',
    }),
  },
};

module.exports = makeExecutableSchema({
  typeDefs,
  resolvers,
  schemaDirectives: {
    computed: computedDirective,
  },
});

Query:

query {
  me {
    fullName
  }
}

Result:

{
  fullName: 'John Doe'
}

Computed property work well with other directives like @rest:

Example:

admin: String @rest(url: "${URL_TO_API}") @computed(value: "Are you admin? $admin")

Directive Parameters

Directive params:

value: String

The calculated value. It can contain other fields from the type in which it is defined.

Example:

@computed(value: "$firstName $lastName")

@computed(value: "$price $")

Contributing

I would love to see your contribution. ❤️

For local development (and testing), all you have to do is to run yarn and then yarn dev. This will start the Apollo server and you are ready to contribute :tada:

Run yarn test (try --watch flag) for unit tests (we are using Jest)

LICENSE

The MIT License (MIT) 2018 - Luke Czyszczonik - mailto:lukasz.czyszczonik@gmail.com

FAQs

Package last updated on 18 Jan 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.