Last active
December 30, 2018 09:10
-
-
Save vertis/66b10ff5184b10fb2f4c48286ec1e484 to your computer and use it in GitHub Desktop.
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
Show hidden characters
{ | |
presets: [ | |
[ | |
"@babel/env", | |
{ | |
targets: { | |
node: "current", | |
}, | |
}, | |
], | |
], | |
plugins: ["@babel/plugin-proposal-class-properties"], | |
} |
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
const createLinkMutation = ` | |
mutation createLink($locationId: ID!, $targetLocationId: ID!, $sphericalCoords: SphericalCoordiantes! ) { | |
createLink(locationId: $locationId, input: { targetLocationId: $targetLocationId, sphericalCoords: $sphericalCoords }) { | |
id | |
} | |
}` |
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
... | |
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 | |
... |
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
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") | |
}) |
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
yarn init | |
yarn add @babel/cli @babel/core @babel/node @babel/plugin-proposal-class-properties @babel/preset-env isomorphic-unfetch |
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
const sphericalCoords = { azimuthAngle: 0, inclinationAngle: 0, radialDistance: 10 } | |
const linkLocation = await gqlQuery({ | |
query: createLinkMutation, | |
variables: { | |
locationId: "1234", | |
targetLocationId: "1234", | |
sphericalCoords | |
}, | |
}) |
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
query { | |
tour(id: "<tourId>") { | |
defaultLocation { | |
id | |
name | |
image { | |
url | |
} | |
links { | |
target { | |
id | |
name | |
} | |
} | |
} | |
} | |
} |
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
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 | |
} | |
} | |
}` |
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
... | |
const updatedTour = await gqlQuery({ | |
query: setStartLocationMutation, | |
variables: { | |
id: tourId, | |
defaultLocationId: "a31ae320-9917-4683-9f68-ebe241169fe5", | |
}, | |
}) | |
... |
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
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() | |
} |
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
query { | |
tour(id: "<tourId>") { | |
id | |
name | |
defaultLocation { | |
id | |
image { | |
url | |
} | |
} | |
locations { | |
id | |
image { | |
url | |
} | |
} | |
} | |
} |
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
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