Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-graphql

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-graphql

Apollo GraphQL utility library

  • 0.3.2
  • npm
  • Socket score

Version published
Weekly downloads
538K
decreased by-1.61%
Maintainers
1
Weekly downloads
 
Created

What is apollo-graphql?

The apollo-graphql npm package provides a set of utilities for working with GraphQL schemas and operations. It is part of the Apollo ecosystem and is designed to help developers build, transform, and analyze GraphQL schemas and queries.

What are apollo-graphql's main functionalities?

Schema Transformation

This feature allows you to transform an existing GraphQL schema. In this example, we create a simple schema with a 'hello' query and then transform it to change the resolver for the 'hello' field.

const { transformSchema } = require('apollo-graphql');
const { makeExecutableSchema } = require('@graphql-tools/schema');

const typeDefs = `
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const schema = makeExecutableSchema({ typeDefs, resolvers });

const transformedSchema = transformSchema(schema, {
  Query: {
    fields: {
      hello: {
        resolve: () => 'Hello transformed world!',
      },
    },
  },
});

console.log(transformedSchema);

Schema Validation

This feature allows you to validate a GraphQL schema. In this example, we build a simple schema and then validate it, logging any validation errors to the console.

const { validateSchema } = require('apollo-graphql');
const { buildSchema } = require('graphql');

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

const errors = validateSchema(schema);

if (errors.length > 0) {
  console.error('Schema validation errors:', errors);
} else {
  console.log('Schema is valid');
}

Operation Parsing

This feature allows you to parse a GraphQL operation (query, mutation, or subscription). In this example, we parse a simple query operation and log the parsed operation to the console.

const { parseOperation } = require('apollo-graphql');

const operation = `
  query GetHello {
    hello
  }
`;

const parsedOperation = parseOperation(operation);

console.log(parsedOperation);

Other packages similar to apollo-graphql

FAQs

Package last updated on 12 Jun 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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc