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

@apollographql/apollo-tools

Package Overview
Dependencies
Maintainers
6
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollographql/apollo-tools

  • 0.5.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1M
decreased by-1.02%
Maintainers
6
Weekly downloads
 
Created

What is @apollographql/apollo-tools?

@apollographql/apollo-tools is a utility library for building GraphQL servers with Apollo. It provides tools for schema manipulation, validation, and other common tasks needed when working with GraphQL schemas.

What are @apollographql/apollo-tools's main functionalities?

Schema Validation

This feature allows you to validate a GraphQL schema to ensure it adheres to the GraphQL specification. The code sample demonstrates how to parse a schema and validate it using the `validateSDL` function.

const { validateSDL } = require('@apollographql/apollo-tools');
const { parse } = require('graphql');

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

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

Schema Transformation

This feature allows you to transform an existing GraphQL schema. The code sample shows how to create an executable schema and then transform it to modify the resolver for the `hello` field.

const { transformSchema } = require('@apollographql/apollo-tools');
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: {
    hello: {
      resolve: () => 'Hello transformed world!',
    },
  },
});

console.log(transformedSchema.getQueryType().getFields().hello.resolve());

Schema Merging

This feature allows you to merge multiple GraphQL schemas into a single schema. The code sample demonstrates how to create two separate schemas and then merge them into one.

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

const schema1 = makeExecutableSchema({
  typeDefs: `
    type Query {
      hello: String
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'Hello from schema1!',
    },
  },
});

const schema2 = makeExecutableSchema({
  typeDefs: `
    type Query {
      world: String
    }
  `,
  resolvers: {
    Query: {
      world: () => 'World from schema2!',
    },
  },
});

const mergedSchema = mergeSchemas({ schemas: [schema1, schema2] });

console.log(mergedSchema.getQueryType().getFields().hello.resolve());
console.log(mergedSchema.getQueryType().getFields().world.resolve());

Other packages similar to @apollographql/apollo-tools

FAQs

Package last updated on 04 May 2022

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