-- graphql.org
-- tjwebb
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="GetTradePriceInput">
<part name="tickerSymbol" element="xsd:string"/>
<part name="time" element="xsd:timeInstant"/>
</message>
<message name="GetTradePriceOutput">
<part name="result" type="xsd:float"/>
</message>
<portType name="StockQuotePortType">
<operation name="GetTradePrice">
<input message="tns:GetTradePriceInput"/>
<output message="tns:GetTradePriceOutput"/>
</operation>
</portType>
<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetTradePrice">
<soap:operation soapAction="http://example.com/GetTradePrice"/>
<input>
<soap:body use="encoded" namespace="http://example.com/stockquote"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://example.com/stockquote"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>>
</binding>
<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort" binding="tns:StockQuoteBinding">
<soap:address location="http://example.com/stockquote"/>
</port>
</service>
</definitions>
POST /sql
select
name,
email,
cats
from user
where cats >= 5
[
{
"name": "tjwebb",
"email": "tjwebb@langa.io",
"cats": 5
}
]
type User {
name: String!
email: String!
cats: Int!
kats: Int @deprecated
}
query {
catUsers: user(cats: 5) {
name
cats
}
normalUsers: user(cats: 0) {
name
cats
}
}
{
"catUsers": [
{
"name": "tjwebb",
"cats": 5
}
],
"normalUsers": [ ]
}
GET /user?name=tjwebb
{
"user": {
"name": "tjwebb",
"email": "tjwebb@langa.io"
}
}
GET /user?name=tjwebb
{
"user": {
"omg": "lol",
"password": "hunter2"
}
}
POST /graphql
user (id: 1) {
name
email
}
{
"user": {
"name": "tjwebb",
"email": "tjwebb@langa.io"
}
}
GET /user?name=tjwebb&fields=email,cats
handler (request, reply) {
const query = request.query
// validate query parameters
knex('user')
.where({ name: query.name })
.select(query.fields.split(','))
.then(result => {
// ... sanitize/validate result
reply(result)
})
}
POST /graphql
handler (request, reply) {
reply(graphql(this.schema, request.payload))
}
-- graphql.org
type UserQuery (email: String, cats: Int) {
name: String
email: String
cats: Int
}
schema {
query: {
user: UserQuery
}
}
type UserQuery (email: String, cats: Int) {
name: String
email: String
cats: Int
}
schema {
query: {
user: UserQuery
}
}
type UserQuery (email: String, cats: Int) {
name: String
email: String
cats: Int
}
class User {
static resolver ({ email, cats }) {
return knex('user').where({ email, cats })
.then(([ record ]) => new User(record))
}
}
type UserQuery (email: String, cats: Int) {
...
dynamicField: Float
}
class User {
static resolver ({ email, cats }) {
return knex('user').where({ email, cats })
.then(([ record ]) => new User(record))
}
get dynamicField () {
return Math.random()
}
}
- Github
- Intuit
- Financial Times
- Shopify
- Wayfair
- Coursera