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

@wundergraph/cosmo-to-apollo-schema

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wundergraph/cosmo-to-apollo-schema

An Apollo Gateway plugin to load the supergraph schema from WunderGraph Cosmo for easy migration.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
73
increased by7200%
Maintainers
0
Weekly downloads
 
Created
Source

Schema Loader

npm version

An Apollo Gateway plugin/helper that helps you to import your subgraphs directly from your Cosmo execution config and compose it into a supergraph sdl. It supports multiple import methods, including:

  • Config File Watcher
  • CDN Polling
  • S3 Polling

Example Usage

import { ApolloGateway } from '@apollo/gateway';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
// 1. Import Schema Loader
import { SchemaLoader } from '@wundergraph/cosmo-to-apollo-schema';

// 2. Configure with file, cdn or s3
const cosmoSchemaLoader = new SchemaLoader({
  filePath: './cosmo-config.json',
});

// 3. Pass it to the gateway subgraphSdl
const gateway = new ApolloGateway({
  supergraphSdl: cosmoSchemaLoader.supergraphSdl,
});

const server = new ApolloServer({
  gateway,
});

startStandaloneServer(server);

Loader Options

At least one of CDN, S3 or file path must be provided.

SchemaLoaderOptions {
  cdn?: CDNOptions;
  s3?: S3Options;
  filePath?: string;

  /*** Defaults to 15000 (15 seconds) */
  pollInterval?: number;
}

CDN

Poll the CDN for config file. The default interval is 15 seconds.

interface CDNOptions {
  endpoint?: string;
  token: string;
  signatureKey?: string;
}

endpoint: The url to the cdn. (default https://cosmo-cdn.wundergraph.com).

token: The token for your Federated Graph. You can generate one with the token create command.

signatureKey: The optional signature key is the one used to sign your config in your admission server.

Usage with Cosmo Cloud

Once you have a token generated using wgc router token create your_graph_name, you can use it in your environment file (.env) as shown below. This fetches from cosmo cloud as the default. Feel free to specify a signatureKey if you have configured admission.

import dotenv from 'dotenv';
import { ApolloGateway } from '@apollo/gateway';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { SchemaLoader } from '@wundergraph/cosmo-to-apollo-schema';

dotenv.config();

// Fetches from Cosmo Cloud CDN by default
const cosmoSchemaLoader = new SchemaLoader({
  cdn: {
    // Token for your federated graph on cosmo.
    token: process.env.GRAPH_TOKEN,
  },
  pollInterval: 3000,
});

const gateway = new ApolloGateway({
  supergraphSdl: cosmoSchemaLoader.supergraphSdl,
});

const server = new ApolloServer({
  gateway,
});

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

File

The plugin watches for any config file changes for the provided path and updates the sdl accordingly.

filePath: string;

S3

Poll your S3 bucket for the execution config. The default interval is 15 seconds.

interface S3Options {
  endpoint: string;
  port?: number;
  accessKey: string;
  secretKey: string;
  region?: Region;
  secure?: boolean;
  bucketName: string;
  objectPath: string;
}

Keywords

FAQs

Package last updated on 10 Dec 2024

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