mirror of
https://github.com/status-im/subspace-docs.git
synced 2025-02-01 07:25:38 +00:00
fix: reactive-graphql docs
This commit is contained in:
parent
10087ce991
commit
1223db334d
@ -32,7 +32,7 @@ module.exports = {
|
||||
'/redux-observable'
|
||||
]
|
||||
},
|
||||
'/graphql',
|
||||
'/reactive-graphql',
|
||||
'/apollo-client'
|
||||
]
|
||||
},
|
||||
|
2
api.md
2
api.md
@ -2,7 +2,7 @@
|
||||
|
||||
## General
|
||||
|
||||
### `new Phoenix(web3Provider, [, options])`
|
||||
### `new Phoenix(web3Provider [, options])`
|
||||
Phoenix constructor.
|
||||
|
||||
**Parameters**
|
||||
|
47
graphql.md
47
graphql.md
@ -1,47 +0,0 @@
|
||||
# Reactive GraphQL
|
||||
```js
|
||||
import { makeExecutableSchema } from "graphql-tools";
|
||||
import gql from "graphql-tag";
|
||||
import {graphql} from "reactive-graphql";
|
||||
|
||||
const typeDefs = `
|
||||
type Escrow {
|
||||
buyer: String!
|
||||
seller: String!
|
||||
escrowId: Int!
|
||||
}
|
||||
type Query {
|
||||
escrows: Escrow!
|
||||
}
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
escrows: () => {
|
||||
return eventSyncer.trackEvent(this.EscrowContract, 'Created', { filter: { buyer: accounts[0] }, fromBlock: 1 })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
const schema = makeExecutableSchema({
|
||||
typeDefs,
|
||||
resolvers
|
||||
});
|
||||
|
||||
const query = gql`
|
||||
query {
|
||||
escrows {
|
||||
buyer
|
||||
seller
|
||||
escrowId
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const stream = graphql(schema, query).pipe(pluck("data", "escrows"));
|
||||
this.setState({
|
||||
escrow: stream
|
||||
});
|
||||
```
|
63
reactive-graphql.md
Normal file
63
reactive-graphql.md
Normal file
@ -0,0 +1,63 @@
|
||||
# reactive-graphql
|
||||
|
||||
Using `reactive-graphql` you can execute GraphQL queries against Phoenix observables to it, and create your own type definitions and queries.
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```js
|
||||
const Phoenix = require('phoenix');
|
||||
const MyContract = require('./MyContract');
|
||||
const { pluck } = require('rxjs/operators');
|
||||
const { makeExecutableSchema } = require("graphql-tools");
|
||||
const gql = require("graphql-tag");
|
||||
const { graphql } = require("reactive-graphql");
|
||||
|
||||
const run = async () => {
|
||||
const eventSyncer = new Phoenix(web3.currentProvider); // Use a valid websocket provider (geth, parity, infura...)
|
||||
await eventSyncer.init();
|
||||
|
||||
const MyContractInstance = ...; // TODO: obtain a web3.eth.contract instance
|
||||
|
||||
const typeDefs = `
|
||||
type MyEvent {
|
||||
someValue: Int
|
||||
anotherValue: String
|
||||
}
|
||||
type Query {
|
||||
myEvents: MyEvent!
|
||||
}
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
myEvents: () => {
|
||||
return eventSyncer.trackEvent(MyContractInstance, 'MyEvent', { filter: {}, fromBlock: 1 })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const schema = makeExecutableSchema({ typeDefs, resolvers });
|
||||
|
||||
const query = gql`
|
||||
query {
|
||||
myEvents {
|
||||
someValue
|
||||
anotherValue
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const stream = graphql(schema, query).pipe(pluck('data', 'myEvents'));
|
||||
stream.subscribe(data => {
|
||||
console.log(data);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
run();
|
||||
```
|
||||
|
||||
::: tip
|
||||
This example is available in [Github](https://github.com/status-im/phoenix/tree/master/examples/reactive-graphql)
|
||||
:::
|
Loading…
x
Reference in New Issue
Block a user