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

apollo

Package Overview
Dependencies
Maintainers
1
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo

Command line tool for Apollo GraphQL

  • 2.34.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is apollo?

The Apollo npm package is a comprehensive suite of tools for building, managing, and querying GraphQL APIs. It provides solutions for both client-side and server-side GraphQL operations, making it a versatile choice for developers working with GraphQL.

What are apollo's main functionalities?

Client-Side GraphQL Queries

Apollo Client allows you to perform GraphQL queries on the client side. This example demonstrates how to set up an Apollo Client instance and perform a simple query to fetch a list of books.

const { ApolloClient, InMemoryCache, gql } = require('@apollo/client');

const client = new ApolloClient({
  uri: 'https://example.com/graphql',
  cache: new InMemoryCache()
});

client.query({
  query: gql`
    query GetBooks {
      books {
        title
        author
      }
    }
  `
}).then(result => console.log(result));

Server-Side GraphQL Schema and Resolvers

Apollo Server allows you to define your GraphQL schema and resolvers on the server side. This example sets up a simple GraphQL server with a schema for books and a resolver that returns a static list of books.

const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
  type Book {
    title: String
    author: String
  }

  type Query {
    books: [Book]
  }
`;

const resolvers = {
  Query: {
    books: () => [
      { title: 'Harry Potter and the Chamber of Secrets', author: 'J.K. Rowling' },
      { title: 'Jurassic Park', author: 'Michael Crichton' }
    ]
  }
};

const server = new ApolloServer({ typeDefs, resolvers });

server.listen().then(({ url }) => {
  console.log(`Server ready at ${url}`);
});

State Management with Apollo Client

Apollo Client provides state management capabilities, allowing you to manage local state alongside remote data. This example demonstrates how to set up a reactive variable and write a local query to the Apollo Client cache.

const { ApolloClient, InMemoryCache, gql, makeVar } = require('@apollo/client');

const cache = new InMemoryCache();

const client = new ApolloClient({
  uri: 'https://example.com/graphql',
  cache
});

const isLoggedInVar = makeVar(false);

client.writeQuery({
  query: gql`
    query IsUserLoggedIn {
      isLoggedIn @client
    }
  `,
  data: {
    isLoggedIn: isLoggedInVar()
  }
});

Other packages similar to apollo

FAQs

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