Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@department/apollo-component
Advanced tools
Readme
A render component for easy querying and mutating of your GraphQL API.
npm install @department/apollo-component
Here is an example of fetching and rendering the data of an imaginary Order
.
import { gql } from "graphql-tag"
import { Query } from "@department/apollo-component"
import SingleOrder, { LoadingOrder } from "components/SingleOrder"
import { GenericError, NotFound } from "components/Errors"
const ShowOrderQuery = gql`
query ShowOrder($id: ID!) {
Order(id: $id) {
...SingleOrder
}
}
${SingleOrder.fragments.SingleOrder}
`;
const Show = ({ id }) => (
<Query gql={ShowOrderQuery} variables={{id}}>
{({ data: { Order }, loading, error, refetch }) =>
loading ? (
<LoadingOrder />
) : error ? (
<GenericError error={error} />
) : (
<SingleOrder {...Order} update={refetch} />
)}
</Query>
));
And another example using <Mutate/>
and fail
-props to raise any errors to
the nearest
React 16+ Error Boundary:
import { gql } from "graphql-tag";
import { Mutate, Query } from "@department/apollo-component";
import { Exception } from "components/Exception";
const IncrementMutation = gql`
mutation IncrementMutation($num: Int!) {
incr(num: $num)
}
`;
const ShowCountQuery = gql`
query ShowCount {
count
}
`;
const IncrementView = ({ id }) => (
<Exception>
<Query gql={ShowCount} wait fail>
{({ data: { count } }) => <div>Current count: {count}</div>}
</Query>
<Mutate gql={IncrementMutation} refetchQueries={["ShowCount"]} fail>
{incr => (
<form onSubmit={e => incr({ num: e.currentTarget.num.valueAsNumber })}>
<input type="number" name="num" value={1} step={1} />
<button>+</button>
</form>
)}
</Mutate>
</Exception>
);
<Query />
gql
wait
lazy
fail
skip
variables
data
the loaded data or an empty objectloading
true while loading (unless the wait
-prop was set)skipped
true if the request was skipped (using the skip
-prop)error
Error object if there was any error (unless the fail
-props was
set)refetch(variables)
call this function rerun query with, optionally, new
variablesfetchMore(opts)
call this function to fetch more (read about the
opts)({ data: { stuff }, loading }) => <div>{loading ? "loading..." : stuff}</div>;
<Mutate />
gql
refetchQueries
optimisticResponse
update
Mutate(variables)
call this function to trigger the mutationskipped
)
data
loading
error
refetch
fetchMore
(mutate, { data: { stuff }, loading }) => (
<button onClick={() => mutate()} disabled={loading}>
{loading ? "loading..." : stuff}
</button>
);
renderState(client, component, options)
For server side rendering renderState()
may be used. It uses a query queue in
the React Context which is populated by <Query/>
in its componentWillMount()
lifecycle method using a naïve component renderer.
It will by default render the tree repeatedly until all queries, without the
lazy
-prop has been completed but the maximum "depth" may be adjusted with the
maxDepth
option.
client
an instance of ApolloClientcomponent
the root component, will be wrapped by a <Provider />
with a
queuemaxDepth
number of attempts to render the tree, defaults to Infinity
(until no more queries are to be found)An example which could be used to server side render.
Note how the <Provider/>
is not needed in renderState()
, it's because it
wraps the component with a special one.
function renderHTML() {
return renderState(client, <App />, { maxDepth: 1 })
.then(() =>
ReactDOM.renderToString(
<Provider client={client}>
<App />
</Provider>
)
)
.catch(err => {
// you can let the error throw here
// or ignore it and let the client side
// handle it inline
console.error("failed to render state:", err);
return renderErrorPage(err);
});
}
FAQs
Render component for your Apollo Client
The npm package @department/apollo-component receives a total of 2 weekly downloads. As such, @department/apollo-component popularity was classified as not popular.
We found that @department/apollo-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.