Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@graphitation/apollo-react-relay-duct-tape
Advanced tools
A compatibility wrapper that provides the react-relay API on top of Apollo Client.
A compatibility wrapper that provides the react-relay API on top of Apollo Client.
The name is a reference to the Apollo 13 mission.
Use this together with @graphitation/apollo-react-relay-duct-tape-compiler to have typings and compiled documents generated.
Install the packages from this repo:
yarn add @graphitation/apollo-react-relay-duct-tape
yarn add --dev @graphitation/apollo-react-relay-duct-tape-compiler
Patch your version of @apollo/client
using the patch found in the patches directory. You can either do so manually or use a tool like patch-package.
For an expedient developer-experience, you will want to install the watchman
tool.
$ brew install watchman
$ choco install watchman
TODO:
We cannot support the default apollo cache keys for fragments on Node [derived] interfaces. Seeing as Node semantics are so core to the ability to provide these APIs, it makes sense to remove the apollo default cache key support.
Copy apollo cache config required from the example app. This includes getting the list of possible types and the dataIdFromObject implementation.
Configure Apollo Client's cache to automatically add __typename
field selections, which concrete types implement the Node
interface, and the type-policies needed to read the watch query data from the store:
import { InMemoryCache } from "@apollo/client";
import { typePoliciesWithGlobalObjectIdStoreKeys as typePolicies } from "@graphitation/apollo-react-relay-duct-tape";
const cache = new InMemoryCache({
addTypename: true,
// Be sure to specify types that implement the Node interface
// See https://www.apollographql.com/docs/react/data/fragments/#using-fragments-with-unions-and-interfaces
possibleTypes: {
Node: ["Todo"],
},
// Either use the `typePoliciesWithGlobalObjectIdStoreKeys` object directly or otherwise extend appropriately. Alternatively you can also use typePoliciesWithDefaultApolloClientStoreKeys
typePolicies: {
Query: {
fields: {
__fragments: {
read: typePolicies.Query.fields.__fragments.read,
},
node: {
read: typePolicies.Query.fields.node.read,
},
},
},
Node: {
fields: {
__fragments: {
read: typePolicies.Node.fields.__fragments.read,
},
},
},
},
// Make sure to specify the dataIdFromObject implementation if you rely on typePoliciesWithGlobalObjectIdStoreKeys
dataIdFromObject(responseObject, keyFieldsContext) {
if (
responseObject.id &&
responseObject.__typename &&
possibleTypes?.Node.includes(responseObject.__typename)
) {
return responseObject.id as string;
}
// fallback to default way of doing it
return defaultDataIdFromObject(responseObject, keyFieldsContext);
},
});
In most cases as in the example app, you can just build the configuration using utilities exported from @graphitation/apollo-react-relay-duct-tape
:
import { InMemoryCache, defaultDataIdFromObject } from "@apollo/client";
import { schema } from "fileWithYourSchema";
import {
typePoliciesWithGlobalObjectIdStoreKeys,
getPossibleTypesAndDataIdFromNode,
} from "@graphitation/apollo-react-relay-duct-tape";
const { possibleTypes, dataIdFromObject } =
getPossibleTypesAndDataIdFromNode(schema);
const cache = new InMemoryCache({
addTypename: true,
possibleTypes, // already makes sure to contain all possible types for Node interface
typePolicies: typePoliciesWithGlobalObjectIdStoreKeys,
dataIdFromObject(responseObject, keyFieldsContext) {
return (
dataIdFromNode(responseObject, keyFieldsContext) ||
defaultDataIdFromObject(responseObject, keyFieldsContext)
);
},
});
Configure webpack to transform your code by replacing inline GraphQL documents with their compiled artefacts:
const config: webpack.Configuration = {
module: {
rules: [
{
test: /.+?\.tsx?$/,
loader: "@graphitation/embedded-document-artefact-loader/webpack",
exclude: /node_modules/,
},
],
},
};
TODO: Have a Node
interface definition
TODO: Add node
root field
Optionally, if you rely on Apollo Client's @client
directive, be sure to explicitly add it to your local copy of your schema, otherwise the compiler will not accept its use.
directive @client(always: Boolean) on FIELD
In a shell, start the compiler and point it to your schema and source. Depending on the size of the code-base a first run may take a while, but subsequent builds should cached. For developer-expedience, it is advised to run the compiler using the watch mode -- provided you have installed the watchman
tool.
$ yarn duct-tape-compiler \
--schema ./path/to/schema.graphql \
--src ./path/to/source \
--watch
TODO:
Node
interface to type that you want to start a new watch query forTODO:
Node
interface instead. The one other type we can assume to exist is the Query
type.FAQs
A compatibility wrapper that provides the react-relay API on top of Apollo Client.
The npm package @graphitation/apollo-react-relay-duct-tape receives a total of 361 weekly downloads. As such, @graphitation/apollo-react-relay-duct-tape popularity was classified as not popular.
We found that @graphitation/apollo-react-relay-duct-tape demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.