Text
Text
Text
THERE IS A REACT WRAPPER FOR GRAPHQL NAMED RELAY.
DESIGNED FOR DOING ALL OPERATIONS IN ONE SINGLE ENDPOINT
GRAPHQL ITSELF DOESN'T DEPEND ON ANY SPECIFIC LANGUAGE.
https://medium.com/chute-engineering/graphql-in-the-age-of-rest-apis-b10f2bf09bba#.m3xh3gubu
query Hero($episode: Episode, $withFriends: Boolean!) {
hero(episode: $episode) {
name
friends @include(if: $withFriends) {
name
}
}
}
import { op, load } from "xhip"
const request = load("request")
export class App {
@op showAppName() {
return {
appName: "xhip example"
}
}
@op showAppVersion() {
return {
appVersion: 1
}
}
@op getServerIP() {
return new Promise((resolve, reject) =>
request.get('https://api.ipify.org?format=json', (error, response, body) => {
if (error) reject(error)
resolve({ ip: JSON.parse(body).ip })
})
).catch(err => {
console.log(err)
})
}
@op echo(say) {
return { say }
}
}
export const app = new App()
Xhip provides its own loader function for isomorphism between server and frontend
import { Server } from "xhip-server"
import { app } from "./app.js"
new xhip.Server(app, {
cors: {
origin: 'http://localhost:21000', // for CORS support
credentials: true,
}
}).listen(8080)
import { Client } from "xhip-client"
const client = new xhip.Client("http://localhost:8080/", { ssl: false })
client.exec([
app.showAppName(),
app.showAppVersion(),
app.echo("hi"),
app.getServerIP()
])).then(...)
{
appName: "xhip example",
appVersion: 1,
say: "hi",
ip: ***.***.***.***
}
http://xhip-example.heroku.com/
Thanks for listening