Simple React GraphQL requests
npm install --save regraph-request
import React from 'react';
import PropTypes from 'prop-types';
import { Query } from 'regraph-request';
const QUERY = `
query Test(
$inputName: String
) {
hello(name: $inputName)
}
`;
export const HelloComponent = ({ data }) => {
if (!data.hello) return <div />;
return <div>{data.hello}</div>;
};
HelloComponent.propTypes = {
username: PropTypes.string,
};
export const Hello = Query(HelloComponent, QUERY, props => ({
inputName: props.username,
}));
export const App = () => {
return (
<RegraphRequest value="https://example.com/graphql">
<Hello />
</RegraphRequest>
);
};
MIT © Altangent