npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hops-apollo-mock-server

v15.2.1

Published

Apollo based mock server for Hops

Downloads

44

Readme

hops-apollo-mock-server

npm

Please see the main Hops Readme for general information and a Getting Started Guide.

This is a preset for Hops in order to start and configure an Apollo Server that can be used for GraphQL mocking to enable faster local development.

Installation

Add this preset (and any other packages that you may need to create an executable schema, such as @graphql-tools/schema) to your existing Hops React project:

npm install --save hops-apollo-mock-server

If you don't already have an existing Hops project read this section on how to set up your first Hops project.

Usage

Creating custom mocks and stitching schemas using Apollo Server

When you are using GraphQL on client side to fetch and bind data into your UI components, it's quite often necessary to work with mock/stub data. There exists tons of feasible reasons why mocking makes sense in daily practices. In summary, the following seem to be the most important.

  • GraphQL schema design in a Frontend-Driven approach
  • Switching between local and remote query execution to work autonomously without an online GraphQL-Server access
  • Faster execution of component integration test using local mock data sets
  • Mock data set support to prove experimental/feature functionality thesis

You can enable mocking by configuring a file that exports an executable schema. Read more about schema stitching and check out this blog post for more examples.

Supports Local GraphQL Playground against your GraphQL schema

open http://localhost:<port>/graphql

GraphiQL Playground

Configuration

Preset Options

| Name | Type | Default | Required | Description | | --- | --- | --- | --- | --- | | fragmentsFile | String | <rootDir>/fragmentTypes.json | no | Where to store the generated fragment types file | | graphqlUri | String | '' | yes | Url to your GraphQL endpoint or mock server | | graphqlSchemaFile | String | '' | no | Path to your GraphQL schema file | | graphqlMockSchemaFile | String | '' | no | Path to your GraphQL schema mocks | | graphqlMockServerPath | String | '/graphql' | no | Path of the mock server endpoint |

fragmentsFile

This option controls where the fragment type information that are used for the IntrospectionFragmentMatcher should be saved.

By default executing $ hops graphql introspect will create a file called fragmentTypes.json in the application root directory.

"hops": {
  "fragmentsFile": "<rootDir>/fragmentTypes.json"
}
graphqlUri

This is the full URI to your GraphQL endpoint which should be used by the client- and server-side when executing requests.

This will also be used to generate fragment type information with $ hops graphql introspect in case no graphqlSchemaFile has been provided.

"hops": {
  "graphqlUri": "https://www.graphqlhub.com/graphql"
}
graphqlSchemaFile

In case your GraphQL server (configured via graphqlUri) does not answer to introspection queries, you can provide the full schema as a file from which the introspection fragment matcher can generate information about unions and interfaces.

"hops": {
  "graphqlSchemaFile": "<rootDir>/schema.graphql"
}
graphqlMockSchemaFile

Specify the path to your stitched mock schema, which is a file that exports an executable schema or a promise that resolves to an executable schema.

{
  "hops": {
    "graphqlMockSchemaFile": "<rootDir>/graphql/index.js"
  }
}

Example mock schema: graphql/index.js

import { makeExecutableSchema } from '@graphql-tools/schema';
import { addMocksToSchema } from '@graphql-tools/mock';
import merge from 'lodash.merge';

import schema1 from './schema1.graphql';
import schema2 from './schema2.graphql';

import resolvers1 from './resolvers1';
import resolvers2 from './resolvers2';

const typeDefs = [schema1, schema2];

const resolvers = merge(resolvers1, resolvers2);

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

export default addMocksToSchema({
  schema: mockSchema,
  mocks: {
    Date: () => '2017-10-17T13:06:22Z',
  },
  preserveResolvers: true,
});