Created
May 21, 2018 20:45
-
-
Save mxmzb/47821669bfb106e52edf9a46a861ffcd to your computer and use it in GitHub Desktop.
graphql nested objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is client side | |
import gql from "graphql-tag"; | |
export const createStoreMutation = gql` | |
mutation( | |
$name: String! | |
$brand: ID! | |
$country: String! | |
$region: String! | |
$locality: String! | |
$postalCode: String! | |
$street: String! | |
) { | |
createStore( | |
data: { | |
name: $name | |
brand: $brand | |
address: { | |
country: $country | |
region: $region | |
locality: $locality | |
postalCode: $postalCode | |
street: $street | |
} | |
} | |
) { | |
name | |
brand { | |
id | |
name | |
} | |
address { | |
country | |
} | |
} | |
} | |
`; | |
# this works perfectly from graphiql: | |
mutation { | |
createStore(data: {name: "a", brand: "5b01f62abeaab70ed18d536e", address: {country: "c", region: "e", locality: "f", postalCode: "g", street: "h"}}) { | |
name | |
brand { | |
id | |
name | |
} | |
address { | |
country | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is server side schema | |
type Mutation { | |
createStore(data: StoreCreateInput): Store! | |
} | |
input StoreCreateInput { | |
name: String! | |
identifier: String | |
brand: ID! | |
address: AddressInput! | |
} | |
input AddressInput { | |
country: String! | |
region: String! | |
locality: String! | |
postalCode: String! | |
street: String! | |
apartment: String | |
} | |
type Store { | |
id: ID! | |
name: String! | |
brand: Brand! | |
address: Address! | |
createdAt: String! | |
} | |
type Brand { | |
id: ID! | |
name: String! | |
logo: String! | |
createdAt: String! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment