fix: adding missing files in react-apollo example
This commit is contained in:
parent
9bcebf17f6
commit
f9b724478b
|
@ -0,0 +1,23 @@
|
||||||
|
import React from "react";
|
||||||
|
import {useQuery} from "@apollo/react-hooks";
|
||||||
|
import {MY_QUERY} from "./queries";
|
||||||
|
|
||||||
|
const MyEvent = () => {
|
||||||
|
const {loading, error, data} = useQuery(MY_QUERY);
|
||||||
|
if (loading) return <div>No data available...</div>;
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
return <div>Error :(</div>;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>The data returned by the query:</p>
|
||||||
|
<ul>
|
||||||
|
<li>someValue: {data.myEvents.someValue}</li>
|
||||||
|
<li>anotherValue: {data.myEvents.anotherValue}</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MyEvent;
|
|
@ -0,0 +1,10 @@
|
||||||
|
import gql from "graphql-tag";
|
||||||
|
|
||||||
|
export const MY_QUERY = gql`
|
||||||
|
query @live {
|
||||||
|
myEvents {
|
||||||
|
someValue
|
||||||
|
anotherValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
|
@ -0,0 +1,23 @@
|
||||||
|
import {makeExecutableSchema} from "graphql-tools";
|
||||||
|
|
||||||
|
const getSchema = MyContractInstance => {
|
||||||
|
const typeDefs = `
|
||||||
|
type MyEvent {
|
||||||
|
someValue: String
|
||||||
|
anotherValue: String
|
||||||
|
}
|
||||||
|
type Query {
|
||||||
|
myEvents: MyEvent!
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const resolvers = {
|
||||||
|
Query: {
|
||||||
|
myEvents: () => MyContractInstance.events.MyEvent.track({filter: {}, fromBlock: 1})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return makeExecutableSchema({typeDefs, resolvers});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getSchema;
|
|
@ -1,12 +1,12 @@
|
||||||
const Subspace = require('@embarklabs/subspace').default;
|
const Subspace = require("@embarklabs/subspace").default;
|
||||||
const web3 = require('./web3');
|
const web3 = require("./web3");
|
||||||
const MyContract = require('./MyContract');
|
const MyContract = require("./MyContract");
|
||||||
const { pluck } = require('rxjs/operators');
|
const {pluck} = require("rxjs/operators");
|
||||||
const {makeExecutableSchema} = require("graphql-tools");
|
const {makeExecutableSchema} = require("graphql-tools");
|
||||||
const gql = require("graphql-tag");
|
const gql = require("graphql-tag");
|
||||||
const {graphql} = require("reactive-graphql");
|
const {graphql} = require("reactive-graphql");
|
||||||
|
|
||||||
const run = (async () => {
|
const run = async () => {
|
||||||
const subspace = new Subspace(web3);
|
const subspace = new Subspace(web3);
|
||||||
await subspace.init();
|
await subspace.init();
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ const run = (async () => {
|
||||||
const resolvers = {
|
const resolvers = {
|
||||||
Query: {
|
Query: {
|
||||||
myEvents: () => {
|
myEvents: () => {
|
||||||
return subspace.trackEvent(MyContractInstance, 'MyEvent', {filter: {}, fromBlock: 1})
|
return subspace.trackEvent(MyContractInstance, "MyEvent", {filter: {}, fromBlock: 1});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -47,11 +47,10 @@ const run = (async () => {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const stream = graphql(schema, query).pipe(pluck('data', 'myEvents'));
|
const stream = graphql(schema, query).pipe(pluck("data", "myEvents"));
|
||||||
stream.subscribe(x => {
|
stream.subscribe(x => {
|
||||||
console.log(x)
|
console.log(x);
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
Loading…
Reference in New Issue