
Security News
CISA Extends MITRE Contract as Crisis Accelerates Alternative CVE Coordination Efforts
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.
hops-apollo-mock-server
Advanced tools
hops-apollo-mock-server
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.
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.
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.
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
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,
});
FAQs
Apollo based mock server for Hops
The npm package hops-apollo-mock-server receives a total of 27 weekly downloads. As such, hops-apollo-mock-server popularity was classified as not popular.
We found that hops-apollo-mock-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Security News
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.
Product
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
Research
The Socket Research Team investigates a malicious npm package that appears to be an Advcash integration but triggers a reverse shell during payment success, targeting servers handling transactions.