Socket
Socket
Sign inDemoInstall

graphql

Package Overview
Dependencies
Maintainers
3
Versions
258
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql

A Query Language and Runtime which can target any service.


Version published
Maintainers
3
Created

What is graphql?

The graphql npm package is the JavaScript reference implementation for GraphQL, a query language for APIs and a runtime for executing those queries by using a type system you define for your data. It allows you to create schemas, define resolvers, and execute GraphQL queries and mutations.

What are graphql's main functionalities?

Creating a GraphQL Schema

This feature allows you to define the shape of your data and the way it can be queried by clients. The code sample demonstrates how to create a simple GraphQL schema with a single root query.

const { GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'Hello world!';
        }
      }
    }
  })
});

Executing a GraphQL Query

This feature allows you to execute GraphQL queries against your schema. The code sample shows how to execute a simple query that asks for the 'hello' field, which resolves to 'Hello world!'.

const { graphql, buildSchema } = require('graphql');

const schema = buildSchema(`
  type Query {
    hello: String
  }
`);

const root = { hello: () => 'Hello world!' };

graphql(schema, '{ hello }', root).then((response) => {
  console.log(response);
});

Defining Resolvers

Resolvers are functions that resolve the value for a type or field in a schema. The code sample shows how to define a resolver for the 'hello' field that returns a string.

const { GraphQLObjectType, GraphQLString } = require('graphql');

const RootQueryType = new GraphQLObjectType({
  name: 'RootQuery',
  fields: {
    hello: {
      type: GraphQLString,
      resolve() {
        return 'Hello world!';
      }
    }
  }
});

Other packages similar to graphql

FAQs

Package last updated on 17 Dec 2017

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc