Skip to content

Instantly share code, notes, and snippets.

@vertis
Last active December 30, 2018 09:10
Show Gist options
  • Save vertis/66b10ff5184b10fb2f4c48286ec1e484 to your computer and use it in GitHub Desktop.
Save vertis/66b10ff5184b10fb2f4c48286ec1e484 to your computer and use it in GitHub Desktop.
{
presets: [
[
"@babel/env",
{
targets: {
node: "current",
},
},
],
],
plugins: ["@babel/plugin-proposal-class-properties"],
}
const createLinkMutation = `
mutation createLink($locationId: ID!, $targetLocationId: ID!, $sphericalCoords: SphericalCoordiantes! ) {
createLink(locationId: $locationId, input: { targetLocationId: $targetLocationId, sphericalCoords: $sphericalCoords }) {
id
}
}`
...
const locations = [
{
name: "Hawaii",
imageUrl: "https://farm5.staticflickr.com/4837/44763080325_6ab31d3bbf_k_d.jpg",
},
]
// Each async create returns a promise so we can use Promise.all to await them all finishing
const createdLocations = await Promise.all(
locations.map(async loc => {
await gqlQuery({
query: createLocationMutation,
variables: {
tourId,
input: loc,
},
})
}),
)
const locationId = createdLocations[0].data.createLocation.id
...
const importTour = async () => {
const createdTour = await gqlQuery({
query: createTourMutation,
variables: {
input: {
name: "My Example Tour",
},
},
})
const tourId = createdTour.data.createTour.id
...
}
importTour().then(function() {
console.log("Done")
})
yarn init
yarn add @babel/cli @babel/core @babel/node @babel/plugin-proposal-class-properties @babel/preset-env isomorphic-unfetch
const sphericalCoords = { azimuthAngle: 0, inclinationAngle: 0, radialDistance: 10 }
const linkLocation = await gqlQuery({
query: createLinkMutation,
variables: {
locationId: "1234",
targetLocationId: "1234",
sphericalCoords
},
})
query {
tour(id: "<tourId>") {
defaultLocation {
id
name
image {
url
}
links {
target {
id
name
}
}
}
}
}
const createTourMutation = `
mutation createTour($input: TourInput!) {
createTour(input: $input) {
id
name
}
}`
const createLocationMutation = `
mutation createLocation($tourId: ID!, $input: CreateLocationInput!) {
createLocation(tourId: $tourId, input: $input) {
id
name
image {
url
}
}
}`
const setStartLocationMutation = `
mutation setStartLocationMutation($id: ID!, $defaultLocationId: ID!) {
updateTour(id: $id, input: { defaultLocationId: $defaultLocationId }) {
id
defaultLocation {
id
}
}
}`
...
const updatedTour = await gqlQuery({
query: setStartLocationMutation,
variables: {
id: tourId,
defaultLocationId: "a31ae320-9917-4683-9f68-ebe241169fe5",
},
})
...
import fetch from "isomorphic-unfetch"
const gqlQuery = async ({ query, variables }) => {
let res = await fetch("https://graphql360.com/graphql", {
method: "POST",
headers: { "Content-Type": "application/json", "x-api-key": process.env.GRAPHQL360_API_KEY },
body: JSON.stringify({ query, variables }),
}).catch(err => {
console.error(err)
throw err
})
return await res.json()
}
query {
tour(id: "<tourId>") {
id
name
defaultLocation {
id
image {
url
}
}
locations {
id
image {
url
}
}
}
}
curl https://graphql360.com/graphql \
-H "x-api-key: <mykey>"
-F operations='{ "query": "mutation uploadImage($image: Upload!) { uploadImage( image: $image) }", "variables": { "image": null } }' \
-F map='{ "0": ["variables.image"] }' \
-F 0=@/<filepath>.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment