├── .github ├── CONTRIBUTING.md └── ISSUE_TEMPLATE.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── auth ├── auth0 │ ├── README.md │ ├── docs │ │ ├── advanced-settings-grant.png │ │ ├── advanced-settings-oauth.png │ │ ├── create-api.png │ │ ├── new-client.png │ │ └── settings.png │ ├── example │ │ ├── index.html │ │ └── index.js │ ├── graphcool.yml │ ├── package.json │ ├── src │ │ ├── auth0Authentication.graphql │ │ └── auth0Authentication.js │ └── types.graphql ├── email-password │ ├── README.md │ ├── graphcool.yml │ ├── package.json │ ├── src │ │ ├── authenticate.graphql │ │ ├── authenticate.ts │ │ ├── loggedInUser.graphql │ │ ├── loggedInUser.ts │ │ ├── signup.graphql │ │ └── signup.ts │ └── types.graphql ├── facebook │ ├── README.md │ ├── USAGE.md │ ├── docs │ │ ├── app-id.png │ │ └── facebook-login-settings.png │ ├── graphcool.yml │ ├── login.html │ ├── package.json │ ├── src │ │ ├── facebookAuthentication.graphql │ │ ├── facebookAuthentication.ts │ │ ├── loggedInUser.graphql │ │ └── loggedInUser.ts │ └── types.graphql ├── github │ ├── README.md │ ├── docs │ │ ├── authorize.png │ │ ├── client-id.png │ │ └── github-login-settings.png │ ├── graphcool.yml │ ├── login.html │ ├── package.json │ ├── src │ │ ├── githubAuthentication.graphql │ │ ├── githubAuthentication.ts │ │ ├── loggedInUser.graphql │ │ └── loggedInUser.ts │ └── types.graphql ├── google │ ├── README.md │ ├── docs │ │ ├── client-id.png │ │ ├── create-client-id.png │ │ ├── create-credentials.png │ │ └── new-project.png │ ├── graphcool.yml │ ├── login.html │ ├── package.json │ ├── src │ │ ├── googleAuthentication.graphql │ │ ├── googleAuthentication.ts │ │ ├── loggedInUser.graphql │ │ └── loggedInUser.ts │ └── types.graphql └── linkedin │ ├── README.md │ ├── graphcool.yml │ ├── login.html │ ├── package.json │ ├── src │ ├── linkedInAuthentication.graphql │ ├── linkedInAuthentication.js │ ├── loggedInUser.graphql │ └── loggedInUser.ts │ └── types.graphql ├── messaging ├── mailgun │ ├── README.md │ ├── graphcool.yml │ ├── package.json │ ├── src │ │ ├── sendEmail.graphql │ │ └── sendEmail.ts │ └── types.graphql ├── pusher │ ├── README.md │ ├── graphcool.yml │ ├── notification.html │ ├── package.json │ ├── src │ │ ├── pushNotification.graphql │ │ └── pushNotification.ts │ └── types.graphql ├── ses │ ├── README.md │ ├── graphcool.yml │ ├── package.json │ ├── src │ │ ├── sendEmail.graphql │ │ └── sendEmail.ts │ └── types.graphql └── twilio │ ├── README.md │ ├── graphcool.yml │ ├── package.json │ ├── src │ ├── sendSms.graphql │ └── sendSms.ts │ └── types.graphql ├── misc ├── fixer-wrapper │ ├── README.md │ ├── graphcool.yml │ ├── package.json │ ├── src │ │ ├── currencies.ts │ │ ├── fixer.graphql │ │ └── fixer.ts │ └── types.graphql └── validate-email │ ├── README.md │ ├── graphcool.yml │ ├── package.json │ ├── src │ └── validateEmail.ts │ └── types.graphql ├── outdated ├── auth │ ├── accountkit-authentication │ │ ├── README.md │ │ ├── accountkit-authentication.graphql │ │ ├── accountkit-authentication.js │ │ ├── app-id.png │ │ ├── login.html │ │ ├── login_success.php │ │ ├── schema-extension.graphql │ │ └── web-settings.png │ ├── auth0-authentication │ │ ├── README.md │ │ ├── assets │ │ │ ├── advanced-settings-grant.png │ │ │ ├── advanced-settings-oauth.png │ │ │ ├── auth0-credentials.png │ │ │ ├── create-user.gif │ │ │ ├── graphcool-logo.svg │ │ │ ├── new-client.png │ │ │ ├── new-schema-extension.gif │ │ │ └── settings.png │ │ ├── auth0-authentication.graphql │ │ ├── functions │ │ │ ├── aws-lambda │ │ │ │ ├── .gitignore │ │ │ │ ├── app.js │ │ │ │ ├── env-dev.yml.template │ │ │ │ ├── handler.js │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ └── services │ │ │ │ │ └── GraphcoolService.js │ │ │ ├── managed │ │ │ │ ├── README.md │ │ │ │ ├── graphcool.yml │ │ │ │ ├── src │ │ │ │ │ ├── authenticate.graphql │ │ │ │ │ └── authenticate.js │ │ │ │ └── types.graphql │ │ │ └── webtask │ │ │ │ ├── auth0-authentication.js │ │ │ │ ├── auth0-authentication.js.secrets │ │ │ │ └── package.json │ │ ├── login-callback.html │ │ ├── login.html │ │ └── schema-extension.graphql │ ├── auth0-database-authentication │ │ ├── README.md │ │ ├── assets │ │ │ ├── advanced-settings-grant.png │ │ │ ├── advanced-settings-oauth.png │ │ │ ├── auth0-credentials.png │ │ │ ├── create-user.gif │ │ │ ├── graphcool-logo.svg │ │ │ ├── new-client.png │ │ │ ├── new-schema-extension.gif │ │ │ └── settings.png │ │ ├── auth0-authentication.graphql │ │ ├── functions │ │ │ ├── aws-lambda │ │ │ │ ├── .gitignore │ │ │ │ ├── app.js │ │ │ │ ├── env-dev.yml.template │ │ │ │ ├── handler.js │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ └── services │ │ │ │ │ └── GraphcoolService.js │ │ │ └── webtask │ │ │ │ ├── auth0-authentication.js │ │ │ │ ├── auth0-authentication.js.secrets │ │ │ │ └── package.json │ │ ├── index.html │ │ └── schema-extension.graphql │ ├── email-user-management │ │ ├── README.md │ │ ├── email-user-management.graphql │ │ └── functions │ │ │ ├── authenticate │ │ │ ├── README.md │ │ │ ├── authenticate.js │ │ │ └── schema-extension.graphql │ │ │ ├── reset-password │ │ │ ├── README.md │ │ │ ├── client │ │ │ │ └── NewPassword.js │ │ │ └── server │ │ │ │ ├── aws-ses-email │ │ │ │ ├── sendPasswordResetEmail.graphql │ │ │ │ └── sendPasswordResetEmail.js │ │ │ │ ├── passwordReset.graphql │ │ │ │ ├── passwordReset.js │ │ │ │ ├── postmark-email │ │ │ │ ├── sendPasswordResetEmail.graphql │ │ │ │ └── sendPasswordResetEmail.js │ │ │ │ ├── sendgrid-email │ │ │ │ ├── sendPasswordResetEmail.graphql │ │ │ │ └── sendPasswordResetEmail.js │ │ │ │ ├── triggerPasswordReset.graphql │ │ │ │ └── triggerPasswordReset.js │ │ │ ├── signup │ │ │ ├── 1-signup-schema.graphql │ │ │ ├── 1-signup.js │ │ │ ├── 2-send-schema.graphql │ │ │ ├── 2-send.js │ │ │ ├── 3-confirm-schema.graphql │ │ │ ├── 3-confirm.js │ │ │ ├── 4-resend-schema.graphql │ │ │ ├── 4-resend.js │ │ │ ├── 5-send-schema.graphql │ │ │ ├── 5-send.js │ │ │ ├── README.md │ │ │ └── client-example.js │ │ │ ├── update-email │ │ │ ├── README.md │ │ │ ├── schema-extension.graphql │ │ │ └── update-email.js │ │ │ └── update-password │ │ │ ├── README.md │ │ │ ├── schema-extension.graphql │ │ │ └── update-password.js │ ├── firebase-authentication │ │ ├── .eslintrc │ │ ├── .flowconfig │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── demo.png │ │ ├── env-dev.yml.EXAMPLE │ │ ├── examples │ │ │ └── one-page │ │ │ │ ├── .gitignore │ │ │ │ ├── index.js │ │ │ │ ├── package.json │ │ │ │ └── webpack.config.js │ │ ├── package.json │ │ ├── schema-extension.sdl │ │ ├── serverless.yml │ │ ├── src │ │ │ ├── firebase-auth.js │ │ │ └── handler.js │ │ └── webpack.config.js │ ├── google-authenticator-authentication │ │ ├── README.md │ │ ├── doc │ │ │ ├── howitworks.jpg │ │ │ └── qr-sample.png │ │ ├── extensions │ │ │ ├── authenticateUser.graphql │ │ │ ├── initializeOTP.graphql │ │ │ ├── registerOTP.graphql │ │ │ └── registerUser.graphql │ │ ├── otp-authentication.js │ │ ├── package.json │ │ └── schema.graphql │ └── sms-authentication │ │ ├── README.md │ │ ├── confirm-code-schema-extension.graphql │ │ ├── confirm-code.js │ │ ├── sms-authentication-schema-extension.graphql │ │ ├── sms-authentication.graphql │ │ └── sms-authentication.js ├── directions-and-geocoding │ ├── address-lookup │ │ ├── README.md │ │ ├── getAddressById.graphql │ │ ├── getAddressById.js │ │ ├── getAddressByPostcodeAndNumber.graphql │ │ └── getAddressByPostcodeAndNumber.js │ ├── google-geocoding │ │ ├── README.md │ │ ├── google-geocoding.graphql │ │ └── google-geocoding.js │ └── openweathermap-api │ │ ├── 16-day-daily-forecast │ │ ├── get-daily-forecast-by-city-and-country.graphql │ │ ├── get-daily-forecast-by-city-and-country.js │ │ ├── get-daily-forecast-by-city.graphql │ │ ├── get-daily-forecast-by-city.js │ │ ├── get-daily-forecast-by-cityid.graphql │ │ ├── get-daily-forecast-by-cityid.js │ │ ├── get-daily-forecast-by-coords.graphql │ │ ├── get-daily-forecast-by-coords.js │ │ ├── get-daily-forecast-by-zipcode-and-country.graphql │ │ ├── get-daily-forecast-by-zipcode-and-country.js │ │ ├── get-daily-forecast-by-zipcode.graphql │ │ └── get-daily-forecast-by-zipcode.js │ │ ├── 5-day-3-hour-forecast │ │ ├── get-forecast-by-city-and-country.graphql │ │ ├── get-forecast-by-city-and-country.js │ │ ├── get-forecast-by-city.graphql │ │ ├── get-forecast-by-city.js │ │ ├── get-forecast-by-cityid.graphql │ │ ├── get-forecast-by-cityid.js │ │ ├── get-forecast-by-coords.graphql │ │ ├── get-forecast-by-coords.js │ │ ├── get-forecast-by-zipcode-and-country.graphql │ │ ├── get-forecast-by-zipcode-and-country.js │ │ ├── get-forecast-by-zipcode.graphql │ │ └── get-forecast-by-zipcode.js │ │ ├── README.md │ │ ├── current-weather-data │ │ ├── get-weather-by-bounding-box.graphql │ │ ├── get-weather-by-bounding-box.js │ │ ├── get-weather-by-circle.graphql │ │ ├── get-weather-by-circle.js │ │ ├── get-weather-by-city-and-country.graphql │ │ ├── get-weather-by-city-and-country.js │ │ ├── get-weather-by-city.graphql │ │ ├── get-weather-by-city.js │ │ ├── get-weather-by-cityid.graphql │ │ ├── get-weather-by-cityid.js │ │ ├── get-weather-by-cityids.graphql │ │ ├── get-weather-by-cityids.js │ │ ├── get-weather-by-coords.graphql │ │ ├── get-weather-by-coords.js │ │ ├── get-weather-by-zipcode-and-country.graphql │ │ ├── get-weather-by-zipcode-and-country.js │ │ ├── get-weather-by-zipcode.graphql │ │ └── get-weather-by-zipcode.js │ │ └── uv-index │ │ ├── get-current-uv.graphql │ │ ├── get-current-uv.js │ │ ├── get-uv-forecast.graphql │ │ ├── get-uv-forecast.js │ │ ├── get-uv-history-period.graphql │ │ ├── get-uv-history-period.js │ │ ├── get-uv-history.graphql │ │ └── get-uv-history.js ├── emails-and-notifications │ ├── one-signal │ │ ├── README.md │ │ ├── one-signal.graphql │ │ └── one-signal.js │ ├── sendgrid-email │ │ ├── README.md │ │ ├── addtolist.js │ │ ├── addtolist_es6.js │ │ ├── email.jpg │ │ ├── email.js │ │ └── sendgrid-email.graphql │ └── slack-bot-notifications │ │ ├── README.md │ │ ├── screenshot.png │ │ └── slack-bot-notifications.js ├── file-handling │ ├── aws-s3-signed-url │ │ ├── README.md │ │ ├── s3.js │ │ └── schema.graphql │ ├── cloudinary-images │ │ ├── README.md │ │ ├── cloudinary.js │ │ ├── graphql.js │ │ ├── schema.graphql │ │ └── upload-avatar.js │ └── file-proxy │ │ ├── .gitignore │ │ ├── README.md │ │ ├── auth-file-proxy │ │ ├── README.md │ │ ├── auth-file-proxy.graphql │ │ ├── auth-file-proxy.js │ │ ├── package.json │ │ └── watcher.js │ │ ├── encrypted-file-proxy.js │ │ ├── everypixel-file-proxy.js │ │ ├── everypixel-sample.jpg │ │ ├── extension-file-proxy.js │ │ ├── logo.png │ │ ├── metadata-file-proxy.js │ │ ├── multiple-file-proxy.js │ │ ├── package.json │ │ ├── schemas │ │ ├── everypixel-file-proxy.graphql │ │ ├── metadata-file-proxy.graphql │ │ └── simple-file-proxy.graphql │ │ ├── simple-file-proxy.js │ │ └── small-logo.png ├── miscellaneous │ ├── generate-slug │ │ ├── README.md │ │ ├── generate-slug.graphql │ │ └── generate-slug.js │ ├── github-fetch-repo │ │ ├── README.md │ │ ├── github-fetch-repo.js │ │ ├── github-repo.graphql │ │ └── github-token.png │ ├── quote-of-the-day │ │ ├── README.md │ │ ├── get-quote-categories.graphql │ │ ├── get-quote-categories.js │ │ ├── get-quote.graphql │ │ └── get-quote.js │ └── tictactoe-gameserver │ │ ├── README.md │ │ ├── functions │ │ ├── computer-makes-move.graphql │ │ ├── computer-makes-move.js │ │ ├── create-gamestate-for-new-game.js │ │ └── update-gamestate-on-move.js │ │ ├── permissions │ │ ├── create-move.graphql │ │ ├── read-game.graphql │ │ └── read-gamestate.graphql │ │ └── schema.graphql ├── payment-and-delivery │ ├── sendcloud-api │ │ ├── README.md │ │ ├── invoices-resource │ │ │ ├── get-user-invoices.graphql │ │ │ └── get-user-invoices.js │ │ ├── label-resource │ │ │ ├── get-label.graphql │ │ │ ├── get-label.js │ │ │ ├── get-labels.graphql │ │ │ └── get-labels.js │ │ ├── parcel-resource │ │ │ ├── cancel-parcel.graphql │ │ │ ├── cancel-parcel.js │ │ │ ├── change-parcel.graphql │ │ │ ├── change-parcel.js │ │ │ ├── create-parcel.graphql │ │ │ ├── create-parcel.js │ │ │ ├── get-parcel.graphql │ │ │ ├── get-parcel.js │ │ │ ├── get-parcels.graphql │ │ │ └── get-parcels.js │ │ ├── parcel-status-resource │ │ │ ├── get-parcel-statuses.graphql │ │ │ └── get-parcel-statuses.js │ │ ├── sender-address-resource │ │ │ ├── get-sender-addresses.graphql │ │ │ └── get-sender-addresses.js │ │ ├── shipping-method-resource │ │ │ ├── get-shipping-method.graphql │ │ │ ├── get-shipping-method.js │ │ │ ├── get-shipping-methods.graphql │ │ │ └── get-shipping-methods.js │ │ └── user-resource │ │ │ ├── get-user.graphql │ │ │ └── get-user.js │ ├── stripe-connect-standard-account │ │ ├── README.md │ │ ├── fetchStripeAccountId.js │ │ ├── schema-extension.graphql │ │ └── stripe-account.graphql │ ├── stripe-coupons │ │ ├── README.md │ │ ├── check-coupon.js │ │ └── stripe-coupons.graphql │ ├── stripe-create-customer-charge │ │ ├── README.md │ │ ├── User.graphql │ │ ├── example-client-side.js │ │ ├── stripe-create-customer-charge.js │ │ └── subscription.graphql │ ├── stripe-create-customer-es6 │ │ ├── .babelrc │ │ ├── .gitignore │ │ ├── README.md │ │ ├── package.json │ │ ├── src │ │ │ ├── constants.js │ │ │ ├── createStripeCustomer.js │ │ │ ├── createStripeCustomer.test.js │ │ │ ├── customer.graphql │ │ │ └── subscription.graphql │ │ ├── test │ │ │ ├── fetchMock.js │ │ │ └── testSetup.js │ │ └── webpack.config.js │ └── stripe-create-customer │ │ ├── README.md │ │ ├── customer.graphql │ │ ├── stripe-create-customer.js │ │ └── subscription.graphql ├── sendgrid │ ├── README.md │ ├── docs │ │ ├── step-01.png │ │ ├── step-02.png │ │ ├── step-03.png │ │ └── step-04.png │ ├── graphcool.yml │ ├── package.json │ ├── src │ │ ├── sendEmail.graphql │ │ └── sendEmail.js │ └── types.graphql └── syncing │ └── algolia │ ├── README.md │ ├── graphcool.yml │ ├── src │ ├── sync.js │ └── syncQuery.graphql │ └── types.graphql └── templates.json /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Issue type: 2 | 3 | I am submitting: 4 | 5 | - [ ] an issue 6 | - [ ] a feature request 7 | 8 | ### Issue Questions: 9 | #### What OS and OS version are you experiencing the issue(s) on? 10 | 11 | 12 | #### What is the expected behavior? 13 | 14 | 15 | #### What is the actual behavior? 16 | 17 | 18 | #### What steps may we take to reproduce the behavior? 19 | 20 | 21 | ### Feature Request Questions: 22 | #### What feature would you like to see added? Please be descriptive. 23 | 24 | 25 | #### Would you be able to submit a PR for this yourself? 26 | 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | package-lock.json 39 | 40 | # BUCK 41 | buck-out/ 42 | \.buckd/ 43 | *.keystore 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/Preview.html 54 | fastlane/screenshots 55 | 56 | jest_* 57 | dist 58 | 59 | .env 60 | .envrc 61 | .graphcoolrc 62 | 63 | yarn.lock 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Graphcool Examples 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /auth/auth0/docs/advanced-settings-grant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/auth0/docs/advanced-settings-grant.png -------------------------------------------------------------------------------- /auth/auth0/docs/advanced-settings-oauth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/auth0/docs/advanced-settings-oauth.png -------------------------------------------------------------------------------- /auth/auth0/docs/create-api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/auth0/docs/create-api.png -------------------------------------------------------------------------------- /auth/auth0/docs/new-client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/auth0/docs/new-client.png -------------------------------------------------------------------------------- /auth/auth0/docs/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/auth0/docs/settings.png -------------------------------------------------------------------------------- /auth/auth0/example/index.js: -------------------------------------------------------------------------------- 1 | function displayAuthResults(accessToken) { 2 | var el = document.getElementById('mutation'); 3 | el.style.visibility = 'visible'; 4 | var mutation = ` 5 | # Run this mutation in the Graphcool Playground to authenticate a user 6 | 7 | mutation { 8 | authenticateUser( 9 | accessToken: "${accessToken}" 10 | ) { 11 | id 12 | token 13 | } 14 | } 15 | `; 16 | el.innerHTML = mutation; 17 | } 18 | 19 | //Replace __AUTH0_CLIENT_ID__, __AUTH0_DOMAIN__ and __AUTH0_API_IDENTIFIER__ with your Auth0 ClientId and Domain 20 | document.addEventListener('DOMContentLoaded', function(event) { 21 | var webAuth = new auth0.WebAuth({ 22 | audience: '__AUTH0_API_IDENTIFIER__', 23 | clientID: '__AUTH0_CLIENT_ID__', 24 | domain: '__AUTH0_DOMAIN__', 25 | redirectUri: 'http://localhost:8080', 26 | responseType: 'token', 27 | scope: 'openid email' 28 | }); 29 | 30 | var elButton = document.getElementById('authenticate'); 31 | elButton.addEventListener('click', function() { 32 | webAuth.authorize(); 33 | }); 34 | 35 | webAuth.parseHash(function(err, authResult) { 36 | if (err) return console.error(err); 37 | if (authResult && authResult.accessToken) { 38 | window.location.hash = ''; 39 | displayAuthResults(authResult.accessToken); 40 | } 41 | console.log(authResult); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /auth/auth0/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | authenticate: 5 | handler: 6 | code: 7 | src: ./src/auth0Authentication.js 8 | environment: 9 | AUTH0_DOMAIN: ${env:AUTH0_DOMAIN} 10 | AUTH0_API_IDENTIFIER: ${env:AUTH0_API_IDENTIFIER} 11 | type: resolver 12 | schema: ./src/auth0Authentication.graphql -------------------------------------------------------------------------------- /auth/auth0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "isomorphic-fetch": "^2.2.1", 5 | "jsonwebtoken": "^8.1.0", 6 | "jwks-rsa": "^1.2.1" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /auth/auth0/src/auth0Authentication.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateUserPayload { 2 | id: String! 3 | token: String! 4 | } 5 | 6 | extend type Mutation { 7 | authenticateUser(accessToken: String!): AuthenticateUserPayload! 8 | } -------------------------------------------------------------------------------- /auth/auth0/types.graphql: -------------------------------------------------------------------------------- 1 | type User @model { 2 | # Required system field: 3 | id: ID! @isUnique # read-only (managed by Graphcool) 4 | 5 | # Optional system fields (remove if not needed): 6 | createdAt: DateTime! # read-only (managed by Graphcool) 7 | updatedAt: DateTime! # read-only (managed by Graphcool) 8 | 9 | email: String 10 | auth0UserId: String @isUnique 11 | } 12 | -------------------------------------------------------------------------------- /auth/email-password/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | # functions 5 | functions: 6 | signup: 7 | type: resolver 8 | schema: src/signup.graphql 9 | handler: 10 | code: src/signup.ts 11 | 12 | authenticate: 13 | type: resolver 14 | schema: src/authenticate.graphql 15 | handler: 16 | code: src/authenticate.ts 17 | 18 | loggedInUser: 19 | type: resolver 20 | schema: src/loggedInUser.graphql 21 | handler: 22 | code: src/loggedInUser.ts 23 | -------------------------------------------------------------------------------- /auth/email-password/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@types/bcryptjs": "^2.4.1", 4 | "@types/validator": "^6.3.0", 5 | "bcryptjs": "^2.4.3", 6 | "graphcool-lib": "^0.1.0", 7 | "graphql-request": "^1.4.0", 8 | "validator": "^9.0.0" 9 | }, 10 | "devDependencies": { 11 | "@types/node": "^8.0.44" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /auth/email-password/src/authenticate.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateUserPayload { 2 | id: ID! 3 | token: String! 4 | } 5 | 6 | extend type Mutation { 7 | authenticateUser(email: String!, password: String!): AuthenticateUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/email-password/src/authenticate.ts: -------------------------------------------------------------------------------- 1 | import { fromEvent, FunctionEvent } from 'graphcool-lib' 2 | import { GraphQLClient } from 'graphql-request' 3 | import * as bcrypt from 'bcryptjs' 4 | 5 | interface User { 6 | id: string 7 | password: string 8 | } 9 | 10 | interface EventData { 11 | email: string 12 | password: string 13 | } 14 | 15 | const SALT_ROUNDS = 10 16 | 17 | export default async (event: FunctionEvent) => { 18 | console.log(event) 19 | 20 | try { 21 | const graphcool = fromEvent(event) 22 | const api = graphcool.api('simple/v1') 23 | 24 | const { email, password } = event.data 25 | 26 | // get user by email 27 | const user: User = await getUserByEmail(api, email) 28 | .then(r => r.User) 29 | 30 | // no user with this email 31 | if (!user) { 32 | return { error: 'Invalid credentials!' } 33 | } 34 | 35 | // check password 36 | const passwordIsCorrect = await bcrypt.compare(password, user.password) 37 | if (!passwordIsCorrect) { 38 | return { error: 'Invalid credentials!' } 39 | } 40 | 41 | // generate node token for existing User node 42 | const token = await graphcool.generateNodeToken(user.id, 'User') 43 | 44 | return { data: { id: user.id, token} } 45 | } catch (e) { 46 | console.log(e) 47 | return { error: 'An unexpected error occured during authentication.' } 48 | } 49 | } 50 | 51 | async function getUserByEmail(api: GraphQLClient, email: string): Promise<{ User }> { 52 | const query = ` 53 | query getUserByEmail($email: String!) { 54 | User(email: $email) { 55 | id 56 | password 57 | } 58 | } 59 | ` 60 | 61 | const variables = { 62 | email, 63 | } 64 | 65 | return api.request<{ User }>(query, variables) 66 | } 67 | -------------------------------------------------------------------------------- /auth/email-password/src/loggedInUser.graphql: -------------------------------------------------------------------------------- 1 | type LoggedInUserPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Query { 6 | # return user data if request contains valid authentication token 7 | loggedInUser: LoggedInUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/email-password/src/loggedInUser.ts: -------------------------------------------------------------------------------- 1 | import { fromEvent, FunctionEvent } from 'graphcool-lib' 2 | import { GraphQLClient } from 'graphql-request' 3 | 4 | interface User { 5 | id: string 6 | } 7 | 8 | export default async (event: FunctionEvent<{}>) => { 9 | console.log(event) 10 | 11 | try { 12 | // no logged in user 13 | if (!event.context.auth || !event.context.auth.nodeId) { 14 | return { data: null } 15 | } 16 | 17 | const userId = event.context.auth.nodeId 18 | const graphcool = fromEvent(event) 19 | const api = graphcool.api('simple/v1') 20 | 21 | // get user by id 22 | const user: User = await getUser(api, userId) 23 | .then(r => r.User) 24 | 25 | // no logged in user 26 | if (!user || !user.id) { 27 | return { data: null } 28 | } 29 | 30 | return { data: { id: user.id } } 31 | } catch (e) { 32 | console.log(e) 33 | return { error: 'An unexpected error occured during authentication.' } 34 | } 35 | } 36 | 37 | async function getUser(api: GraphQLClient, id: string): Promise<{ User }> { 38 | const query = ` 39 | query getUser($id: ID!) { 40 | User(id: $id) { 41 | id 42 | } 43 | } 44 | ` 45 | 46 | const variables = { 47 | id, 48 | } 49 | 50 | return api.request<{ User }>(query, variables) 51 | } -------------------------------------------------------------------------------- /auth/email-password/src/signup.graphql: -------------------------------------------------------------------------------- 1 | type SignupUserPayload { 2 | id: ID! 3 | token: String! 4 | } 5 | 6 | extend type Mutation { 7 | signupUser(email: String!, password: String!): SignupUserPayload 8 | } -------------------------------------------------------------------------------- /auth/email-password/types.graphql: -------------------------------------------------------------------------------- 1 | type User @model { 2 | # Required system field: 3 | id: ID! @isUnique # read-only (managed by Graphcool) 4 | 5 | # Optional system fields (remove if not needed): 6 | createdAt: DateTime! # read-only (managed by Graphcool) 7 | updatedAt: DateTime! # read-only (managed by Graphcool) 8 | 9 | email: String! @isUnique 10 | password: String! 11 | } 12 | -------------------------------------------------------------------------------- /auth/facebook/USAGE.md: -------------------------------------------------------------------------------- 1 | # facebook 2 | 3 | Add Facebook Authentication to your Graphcool project 🎁 4 | 5 | ## Getting Started 6 | 7 | ### 1. Add the template to your Graphcool service 8 | 9 | ```sh 10 | graphcool add-template graphcool/templates/auth/facebook 11 | ``` 12 | 13 | ### 2. Uncomment lines in `graphcool.yml` and `types.graphql` 14 | 15 | The [`add-template`](https://www.graph.cool/docs/reference/graphcool-cli/commands-aiteerae6l#graphcool-add-template) command is performing three major steps: 16 | 17 | 1. Download the source files from the [`src`](./src) directory and put them into your service's `src` directory (into a subdirectory called `email-password`). 18 | 2. Download the contents from [`graphcool.yml`](./graphcool.yml) and append them as comments to your service's `graphcool.yml`. 19 | 3. Download the contents from [`types.graphql`](./types.graphql) and append them as comments to your service's `types.graphql`. 20 | 21 | In order for the changes to take effect, you need to manually uncomment all the lines that have been added by the `add-template` command. 22 | 23 | ### 3. Deploy the service 24 | 25 | Finally, you need to install the [node dependencies](./package.json#L2) and apply all the changes you just made by deploying the service: 26 | 27 | ```sh 28 | npm install 29 | graphcool deploy 30 | ``` 31 | -------------------------------------------------------------------------------- /auth/facebook/docs/app-id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/facebook/docs/app-id.png -------------------------------------------------------------------------------- /auth/facebook/docs/facebook-login-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/facebook/docs/facebook-login-settings.png -------------------------------------------------------------------------------- /auth/facebook/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | facebookAuthentication: 5 | handler: 6 | code: 7 | src: ./src/facebookAuthentication.ts 8 | type: resolver 9 | schema: ./src/facebookAuthentication.graphql 10 | loggedInUser: 11 | handler: 12 | code: 13 | src: ./src/loggedInUser.ts 14 | type: resolver 15 | schema: ./src/loggedInUser.graphql -------------------------------------------------------------------------------- /auth/facebook/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 13 | 14 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /auth/facebook/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "graphql-request": "^1.4.0" 5 | }, 6 | "devDependencies": { 7 | "@types/node": "^8.0.44" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /auth/facebook/src/facebookAuthentication.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateUserPayload { 2 | id: ID! 3 | token: String! 4 | } 5 | 6 | extend type Mutation { 7 | authenticateUser(facebookToken: String!): AuthenticateUserPayload! 8 | } -------------------------------------------------------------------------------- /auth/facebook/src/loggedInUser.graphql: -------------------------------------------------------------------------------- 1 | type LoggedInUserPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Query { 6 | # return user data if request contains valid authentication token 7 | loggedInUser: LoggedInUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/facebook/src/loggedInUser.ts: -------------------------------------------------------------------------------- 1 | import { fromEvent, FunctionEvent } from 'graphcool-lib' 2 | import { GraphQLClient } from 'graphql-request' 3 | 4 | interface User { 5 | id: string 6 | } 7 | 8 | export default async (event: FunctionEvent<{}>) => { 9 | console.log(event) 10 | 11 | try { 12 | // no logged in user 13 | if (!event.context.auth || !event.context.auth.nodeId) { 14 | return { data: null } 15 | } 16 | 17 | const userId = event.context.auth.nodeId 18 | const graphcool = fromEvent(event) 19 | const api = graphcool.api('simple/v1') 20 | 21 | // get user by id 22 | const user: User = await getUser(api, userId) 23 | .then(r => r.User) 24 | 25 | // no logged in user 26 | if (!user || !user.id) { 27 | return { data: null } 28 | } 29 | 30 | return { data: { id: user.id } } 31 | } catch (e) { 32 | console.log(e) 33 | return { error: 'An unexpected error occured during authentication.' } 34 | } 35 | } 36 | 37 | async function getUser(api: GraphQLClient, id: string): Promise<{ User }> { 38 | const query = ` 39 | query getUser($id: ID!) { 40 | User(id: $id) { 41 | id 42 | } 43 | } 44 | ` 45 | 46 | const variables = { 47 | id, 48 | } 49 | 50 | return api.request<{ User }>(query, variables) 51 | } -------------------------------------------------------------------------------- /auth/facebook/types.graphql: -------------------------------------------------------------------------------- 1 | type User @model { 2 | # Required system field: 3 | id: ID! @isUnique # read-only (managed by Graphcool) 4 | 5 | # Optional system fields (remove if not needed): 6 | createdAt: DateTime! # read-only (managed by Graphcool) 7 | updatedAt: DateTime! # read-only (managed by Graphcool) 8 | 9 | facebookUserId: String @isUnique 10 | email: String # optional, because it's obtained from Facebook API 11 | } 12 | -------------------------------------------------------------------------------- /auth/github/docs/authorize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/github/docs/authorize.png -------------------------------------------------------------------------------- /auth/github/docs/client-id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/github/docs/client-id.png -------------------------------------------------------------------------------- /auth/github/docs/github-login-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/github/docs/github-login-settings.png -------------------------------------------------------------------------------- /auth/github/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | # functions 5 | functions: 6 | githubAuthentication: 7 | handler: 8 | code: 9 | src: ./src/githubAuthentication.ts 10 | environment: 11 | GITHUB_CLIENT_ID: ${env:GITHUB_CLIENT_ID} 12 | GITHUB_CLIENT_SECRET: ${env:GITHUB_CLIENT_SECRET} 13 | type: resolver 14 | schema: ./src/githubAuthentication.graphql 15 | loggedInUser: 16 | handler: 17 | code: 18 | src: ./src/loggedInUser.ts 19 | type: resolver 20 | schema: ./src/loggedInUser.graphql 21 | -------------------------------------------------------------------------------- /auth/github/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /auth/github/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "graphql-request": "^1.4.0", 5 | "isomorphic-fetch": "^2.2.1" 6 | }, 7 | "devDependencies": { 8 | "@types/node": "^8.0.44" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /auth/github/src/githubAuthentication.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateUserPayload { 2 | id: ID! 3 | token: String! 4 | } 5 | 6 | extend type Mutation { 7 | authenticateUser(githubCode: String!): AuthenticateUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/github/src/loggedInUser.graphql: -------------------------------------------------------------------------------- 1 | type LoggedInUserPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Query { 6 | # return user data if request contains valid authentication token 7 | loggedInUser: LoggedInUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/github/src/loggedInUser.ts: -------------------------------------------------------------------------------- 1 | import { fromEvent, FunctionEvent } from 'graphcool-lib' 2 | import { GraphQLClient } from 'graphql-request' 3 | 4 | interface User { 5 | id: string 6 | } 7 | 8 | export default async (event: FunctionEvent<{}>) => { 9 | console.log(event) 10 | 11 | try { 12 | // no logged in user 13 | if (!event.context.auth || !event.context.auth.nodeId) { 14 | return { data: null } 15 | } 16 | 17 | const userId = event.context.auth.nodeId 18 | const graphcool = fromEvent(event) 19 | const api = graphcool.api('simple/v1') 20 | 21 | // get user by id 22 | const user: User = await getUser(api, userId) 23 | .then(r => r.User) 24 | 25 | // no logged in user 26 | if (!user || !user.id) { 27 | return { data: null } 28 | } 29 | 30 | return { data: { id: user.id } } 31 | } catch (e) { 32 | console.log(e) 33 | return { error: 'An unexpected error occured during authentication.' } 34 | } 35 | } 36 | 37 | async function getUser(api: GraphQLClient, id: string): Promise<{ User }> { 38 | const query = ` 39 | query getUser($id: ID!) { 40 | User(id: $id) { 41 | id 42 | } 43 | } 44 | ` 45 | 46 | const variables = { 47 | id, 48 | } 49 | 50 | return api.request<{ User }>(query, variables) 51 | } -------------------------------------------------------------------------------- /auth/github/types.graphql: -------------------------------------------------------------------------------- 1 | type User @model { 2 | # Required system field: 3 | id: ID! @isUnique # read-only (managed by Graphcool) 4 | 5 | # Optional system fields (remove if not needed): 6 | createdAt: DateTime! # read-only (managed by Graphcool) 7 | updatedAt: DateTime! # read-only (managed by Graphcool) 8 | 9 | githubUserId: String @isUnique 10 | } 11 | -------------------------------------------------------------------------------- /auth/google/docs/client-id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/google/docs/client-id.png -------------------------------------------------------------------------------- /auth/google/docs/create-client-id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/google/docs/create-client-id.png -------------------------------------------------------------------------------- /auth/google/docs/create-credentials.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/google/docs/create-credentials.png -------------------------------------------------------------------------------- /auth/google/docs/new-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/auth/google/docs/new-project.png -------------------------------------------------------------------------------- /auth/google/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | googleAuthentication: 5 | handler: 6 | code: 7 | src: ./src/googleAuthentication.ts 8 | type: resolver 9 | schema: ./src/googleAuthentication.graphql 10 | loggedInUser: 11 | handler: 12 | code: 13 | src: ./src/loggedInUser.ts 14 | type: resolver 15 | schema: ./src/loggedInUser.graphql -------------------------------------------------------------------------------- /auth/google/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /auth/google/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "graphql-request": "^1.4.0", 5 | "isomorphic-fetch": "^2.2.1" 6 | }, 7 | "devDependencies": { 8 | "@types/node": "^8.0.44" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /auth/google/src/googleAuthentication.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateGoogleUserPayload { 2 | id: ID! 3 | token: String! 4 | } 5 | 6 | extend type Mutation { 7 | authenticateGoogleUser(googleToken: String!): AuthenticateGoogleUserPayload! 8 | } -------------------------------------------------------------------------------- /auth/google/src/loggedInUser.graphql: -------------------------------------------------------------------------------- 1 | type LoggedInUserPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Query { 6 | # return user data if request contains valid authentication token 7 | loggedInUser: LoggedInUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/google/src/loggedInUser.ts: -------------------------------------------------------------------------------- 1 | import { fromEvent, FunctionEvent } from 'graphcool-lib' 2 | import { GraphQLClient } from 'graphql-request' 3 | 4 | interface User { 5 | id: string 6 | } 7 | 8 | export default async (event: FunctionEvent<{}>) => { 9 | console.log(event) 10 | 11 | try { 12 | // no logged in user 13 | if (!event.context.auth || !event.context.auth.nodeId) { 14 | return { data: null } 15 | } 16 | 17 | const userId = event.context.auth.nodeId 18 | const graphcool = fromEvent(event) 19 | const api = graphcool.api('simple/v1') 20 | 21 | // get user by id 22 | const user: User = await getUser(api, userId) 23 | .then(r => r.User) 24 | 25 | // no logged in user 26 | if (!user || !user.id) { 27 | return { data: null } 28 | } 29 | 30 | return { data: { id: user.id } } 31 | } catch (e) { 32 | console.log(e) 33 | return { error: 'An unexpected error occured during authentication.' } 34 | } 35 | } 36 | 37 | async function getUser(api: GraphQLClient, id: string): Promise<{ User }> { 38 | const query = ` 39 | query getUser($id: ID!) { 40 | User(id: $id) { 41 | id 42 | } 43 | } 44 | ` 45 | 46 | const variables = { 47 | id, 48 | } 49 | 50 | return api.request<{ User }>(query, variables) 51 | } -------------------------------------------------------------------------------- /auth/google/types.graphql: -------------------------------------------------------------------------------- 1 | type User @model { 2 | # Required system field: 3 | id: ID! @isUnique # read-only (managed by Graphcool) 4 | 5 | # Optional system fields (remove if not needed): 6 | createdAt: DateTime! # read-only (managed by Graphcool) 7 | updatedAt: DateTime! # read-only (managed by Graphcool) 8 | 9 | googleUserId: String @isUnique 10 | } 11 | -------------------------------------------------------------------------------- /auth/linkedin/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | linkedInAuthentication: 5 | handler: 6 | code: 7 | src: ./src/linkedInAuthentication.ts 8 | type: resolver 9 | schema: ./src/linkedInAuthentication.graphql 10 | loggedInUser: 11 | handler: 12 | code: 13 | src: ./src/loggedInUser.ts 14 | type: resolver 15 | schema: ./src/loggedInUser.graphql -------------------------------------------------------------------------------- /auth/linkedin/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /auth/linkedin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "graphql-request": "^1.4.0" 5 | }, 6 | "devDependencies": { 7 | "@types/node": "^8.0.44" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /auth/linkedin/src/linkedInAuthentication.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateLinkedInUserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateLinkedInUser(linkedInToken: String!): AuthenticateLinkedInUserPayload 7 | } 8 | -------------------------------------------------------------------------------- /auth/linkedin/src/loggedInUser.graphql: -------------------------------------------------------------------------------- 1 | type LoggedInUserPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Query { 6 | # return user data if request contains valid authentication token 7 | loggedInUser: LoggedInUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /auth/linkedin/src/loggedInUser.ts: -------------------------------------------------------------------------------- 1 | import { fromEvent, FunctionEvent } from 'graphcool-lib' 2 | import { GraphQLClient } from 'graphql-request' 3 | 4 | interface User { 5 | id: string 6 | } 7 | 8 | export default async (event: FunctionEvent<{}>) => { 9 | console.log(event) 10 | 11 | try { 12 | // no logged in user 13 | if (!event.context.auth || !event.context.auth.nodeId) { 14 | return { data: null } 15 | } 16 | 17 | const userId = event.context.auth.nodeId 18 | const graphcool = fromEvent(event) 19 | const api = graphcool.api('simple/v1') 20 | 21 | // get user by id 22 | const user: User = await getUser(api, userId) 23 | .then(r => r.User) 24 | 25 | // no logged in user 26 | if (!user || !user.id) { 27 | return { data: null } 28 | } 29 | 30 | return { data: { id: user.id } } 31 | } catch (e) { 32 | console.log(e) 33 | return { error: 'An unexpected error occured during authentication.' } 34 | } 35 | } 36 | 37 | async function getUser(api: GraphQLClient, id: string): Promise<{ User }> { 38 | const query = ` 39 | query getUser($id: ID!) { 40 | User(id: $id) { 41 | id 42 | } 43 | } 44 | ` 45 | 46 | const variables = { 47 | id, 48 | } 49 | 50 | return api.request<{ User }>(query, variables) 51 | } -------------------------------------------------------------------------------- /auth/linkedin/types.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | # Required system field: 3 | id: ID! @isUnique # read-only (managed by Graphcool) 4 | 5 | # Optional system fields (remove if not needed): 6 | createdAt: DateTime! # read-only (managed by Graphcool) 7 | updatedAt: DateTime! # read-only (managed by Graphcool) 8 | 9 | # Make it required if LinkedIn is the only authorization method in your app 10 | linkedInUserId: String @isUnique 11 | } 12 | -------------------------------------------------------------------------------- /messaging/mailgun/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | # functions 5 | functions: 6 | sendEmail: 7 | handler: 8 | code: 9 | src: ./src/sendEmail.ts 10 | environment: 11 | MAILGUN_API_KEY: ${env:MAILGUN_API_KEY} 12 | MAILGUN_DOMAIN: ${env:MAILGUN_DOMAIN} 13 | type: resolver 14 | schema: ./src/sendEmail.graphql 15 | -------------------------------------------------------------------------------- /messaging/mailgun/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@types/form-data": "^2.2.0", 4 | "form-data": "^2.3.1", 5 | "graphcool-lib": "^0.1.0", 6 | "isomorphic-fetch": "^2.2.1" 7 | }, 8 | "devDependencies": { 9 | "@types/node": "^8.0.45" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /messaging/mailgun/src/sendEmail.graphql: -------------------------------------------------------------------------------- 1 | type MailgunEmailPayload { 2 | success: Boolean! 3 | } 4 | 5 | extend type Mutation { 6 | sendMailgunEmail( 7 | tag: String! 8 | from: String! 9 | to: [String!]! 10 | subject: String! 11 | text: String! 12 | recipientVariables: Json 13 | ): MailgunEmailPayload 14 | } 15 | -------------------------------------------------------------------------------- /messaging/mailgun/types.graphql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/messaging/mailgun/types.graphql -------------------------------------------------------------------------------- /messaging/pusher/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | functions: 5 | pushNotification: 6 | handler: 7 | code: 8 | src: ./src/pushNotification.ts 9 | environment: 10 | PUSHER_APP_ID: ${env:PUSHER_APP_ID} 11 | PUSHER_KEY: ${env:PUSHER_KEY} 12 | PUSHER_SECRET: ${env:PUSHER_SECRET} 13 | PUSHER_CLUSTER: ${env:PUSHER_CLUSTER} 14 | type: resolver 15 | schema: ./src/pushNotification.graphql 16 | -------------------------------------------------------------------------------- /messaging/pusher/notification.html: -------------------------------------------------------------------------------- 1 | 2 | Pusher Test 3 | 4 | 29 | 30 |

31 | Graphcool Push Notifications 32 |

33 | 34 | 35 | -------------------------------------------------------------------------------- /messaging/pusher/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "pusher": "^1.5.1" 5 | }, 6 | "devDependencies": { 7 | "@types/node": "^8.0.45" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /messaging/pusher/src/pushNotification.graphql: -------------------------------------------------------------------------------- 1 | type PushNotificationPayload { 2 | success: Boolean! 3 | } 4 | 5 | extend type Mutation { 6 | pushNotification( 7 | channels: [String!]! 8 | event: String! 9 | message: String! 10 | ): PushNotificationPayload! 11 | } 12 | -------------------------------------------------------------------------------- /messaging/pusher/types.graphql: -------------------------------------------------------------------------------- 1 | # This file contains the GraphQL Types 2 | -------------------------------------------------------------------------------- /messaging/ses/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | sendEmail: 5 | handler: 6 | code: 7 | src: src/sendEmail.ts 8 | environment: 9 | ACCESS_KEY_ID: ${env:ACCESS_KEY_ID} 10 | SECRET_ACCESS_KEY: ${env:SECRET_ACCESS_KEY} 11 | REGION: ${env:REGION} 12 | type: resolver 13 | schema: src/sendEmail.graphql 14 | -------------------------------------------------------------------------------- /messaging/ses/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "aws-sdk": "^2.135.0", 4 | "graphcool-lib": "^0.1.3" 5 | }, 6 | "devDependencies": { 7 | "@types/node": "^8.0.45" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /messaging/ses/src/sendEmail.graphql: -------------------------------------------------------------------------------- 1 | type SesEmailPayload { 2 | success: Boolean! 3 | } 4 | 5 | extend type Mutation { 6 | sendSesEmail( 7 | from: String! 8 | to: [String!]! 9 | subject: String! 10 | text: String! 11 | html: String! 12 | ): SesEmailPayload! 13 | } -------------------------------------------------------------------------------- /messaging/ses/types.graphql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/messaging/ses/types.graphql -------------------------------------------------------------------------------- /messaging/twilio/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | functions: 5 | sendSms: 6 | handler: 7 | code: 8 | src: ./src/sendSms.ts 9 | environment: 10 | TWILIO_ACCOUNT_SID: ${env:TWILIO_ACCOUNT_SID} 11 | TWILIO_AUTH_TOKEN: ${env:TWILIO_AUTH_TOKEN} 12 | type: resolver 13 | schema: ./src/sendSms.graphql 14 | -------------------------------------------------------------------------------- /messaging/twilio/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@types/twilio": "0.0.9", 4 | "graphcool-lib": "^0.1.0", 5 | "twilio": "^3.8.0" 6 | }, 7 | "devDependencies": { 8 | "@types/node": "^8.0.45" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /messaging/twilio/src/sendSms.graphql: -------------------------------------------------------------------------------- 1 | type TwilioSmsPayload { 2 | sid: String! 3 | } 4 | 5 | extend type Mutation { 6 | sendSms( 7 | to: String! 8 | from: String! 9 | body: String! 10 | mediaUrl: String 11 | ): TwilioSmsPayload 12 | } 13 | -------------------------------------------------------------------------------- /messaging/twilio/src/sendSms.ts: -------------------------------------------------------------------------------- 1 | import { FunctionEvent } from 'graphcool-lib' 2 | import * as twilio from 'twilio' 3 | 4 | interface EventData { 5 | to: string 6 | from: string 7 | body: string 8 | mediaUrl: string | null 9 | } 10 | 11 | export default async (event: FunctionEvent) => { 12 | 13 | if (!process.env['TWILIO_ACCOUNT_SID']) { 14 | console.log('Please provide a valid twilio account sid!') 15 | return { error: 'Module not configured correctly.' } 16 | } 17 | 18 | if (!process.env['TWILIO_AUTH_TOKEN']) { 19 | console.log('Please provide a valid twilio auth token!') 20 | return { error: 'Module not configured correctly.' } 21 | } 22 | 23 | try { 24 | const accountSid = process.env['TWILIO_ACCOUNT_SID'] 25 | const authToken = process.env['TWILIO_AUTH_TOKEN'] 26 | const client = twilio(accountSid, authToken) 27 | 28 | const { to, from, body, mediaUrl } = event.data 29 | 30 | const data = await client.messages 31 | .create({ 32 | to: to, 33 | from: from, 34 | body: body, 35 | mediaUrl: mediaUrl 36 | }) 37 | 38 | return { data: { sid: data.sid } } 39 | } catch(error) { 40 | console.log(error) 41 | return { error: 'Unexpected error occured.' } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /messaging/twilio/types.graphql: -------------------------------------------------------------------------------- 1 | # This file contains the GraphQL Types 2 | -------------------------------------------------------------------------------- /misc/fixer-wrapper/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | fixer-wrapper: 5 | type: resolver 6 | schema: ./src/fixer.graphql 7 | handler: 8 | code: 9 | src: ./src/fixer.ts -------------------------------------------------------------------------------- /misc/fixer-wrapper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "isomorphic-fetch": "^2.2.1" 4 | }, 5 | "devDependencies": { 6 | "@types/node": "^8.0.44" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /misc/fixer-wrapper/src/currencies.ts: -------------------------------------------------------------------------------- 1 | export enum Currencies { 2 | AUD = 'AUD', 3 | BGN = 'BGN', 4 | BRL = 'BRL', 5 | CAD = 'CAD', 6 | CHF = 'CHF', 7 | CNY = 'CNY', 8 | CZK = 'CZK', 9 | DKK = 'DKK', 10 | EUR = 'EUR', 11 | GBP = 'GBP', 12 | HKD = 'HKD', 13 | HRK = 'HRK', 14 | HUF = 'HUF', 15 | IDR = 'IDR', 16 | ILS = 'ILS', 17 | INR = 'INR', 18 | JPY = 'JPY', 19 | KRW = 'KRW', 20 | MXN = 'MXN', 21 | MYR = 'MYR', 22 | NOK = 'NOK', 23 | NZD = 'NZD', 24 | PHP = 'PHP', 25 | PLN = 'PLN', 26 | RON = 'RON', 27 | RUB = 'RUB', 28 | SEK = 'SEK', 29 | SGD = 'SGD', 30 | THB = 'THB', 31 | TRY = 'TRY', 32 | USD = 'USD', 33 | ZAR = 'ZAR', 34 | } -------------------------------------------------------------------------------- /misc/fixer-wrapper/src/fixer.graphql: -------------------------------------------------------------------------------- 1 | type FixerPayload { 2 | base: String! 3 | date: DateTime! 4 | 5 | # base will be null 6 | aud: Float 7 | bgn: Float 8 | brl: Float 9 | cad: Float 10 | chf: Float 11 | cny: Float 12 | czk: Float 13 | dkk: Float 14 | eur: Float 15 | gbp: Float 16 | hkd: Float 17 | hrk: Float 18 | huf: Float 19 | idr: Float 20 | ils: Float 21 | inr: Float 22 | jpy: Float 23 | krw: Float 24 | mxn: Float 25 | myr: Float 26 | nok: Float 27 | nzd: Float 28 | php: Float 29 | pln: Float 30 | ron: Float 31 | rub: Float 32 | sek: Float 33 | sgd: Float 34 | thb: Float 35 | try: Float 36 | usd: Float 37 | zar: Float 38 | } 39 | 40 | extend type Query { 41 | fixer(base: String, date: DateTime): FixerPayload 42 | } 43 | -------------------------------------------------------------------------------- /misc/fixer-wrapper/types.graphql: -------------------------------------------------------------------------------- 1 | # no model types needed 2 | 3 | # enums are not yet supported, see https://github.com/graphcool/graphcool/issues/742 4 | enum Currency { 5 | AUD 6 | BGN 7 | BRL 8 | CAD 9 | CHF 10 | CNY 11 | CZK 12 | DKK 13 | EUR 14 | GBP 15 | HKD 16 | HRK 17 | HUF 18 | IDR 19 | ILS 20 | INR 21 | JPY 22 | KRW 23 | MXN 24 | MYR 25 | NOK 26 | NZD 27 | PHP 28 | PLN 29 | RON 30 | RUB 31 | SEK 32 | SGD 33 | THB 34 | TRY 35 | USD 36 | ZAR 37 | } 38 | -------------------------------------------------------------------------------- /misc/validate-email/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | validateEmail: 5 | type: operationBefore 6 | operation: Customer.create 7 | handler: 8 | code: src/validateEmail.ts 9 | 10 | # development permissions 11 | permissions: 12 | - operation: "*" 13 | -------------------------------------------------------------------------------- /misc/validate-email/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-email", 3 | "version": "1.0.0", 4 | "description": "My Graphcool Service", 5 | "dependencies": { 6 | "graphcool-lib": "^0.1.4", 7 | "validator": "^9.0.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /misc/validate-email/src/validateEmail.ts: -------------------------------------------------------------------------------- 1 | // 1. Import npm modules 2 | import * as validator from 'validator' 3 | import { FunctionEvent } from 'graphcool-lib' 4 | 5 | // 2. Define type of event data 6 | interface EventData { 7 | id: string 8 | name: string 9 | email: string 10 | } 11 | 12 | export default async (event: FunctionEvent) => { 13 | // 3. Transform Email to lowercase 14 | event.data.email = event.data.email.toLowerCase() 15 | 16 | // 4. Validate Email 17 | if (!validator.isEmail(event.data.email)) { 18 | return { error: `${event.data.email} is not a valid email!` } 19 | } 20 | 21 | // 5. Return transformed data 22 | return { data: event.data } 23 | } -------------------------------------------------------------------------------- /misc/validate-email/types.graphql: -------------------------------------------------------------------------------- 1 | type Customer @model { 2 | id: ID! @isUnique 3 | name: String! 4 | email: String! 5 | } -------------------------------------------------------------------------------- /outdated/auth/accountkit-authentication/accountkit-authentication.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: ID! 3 | 4 | # Must be unique 5 | # Make it required if Account Kit is the only authorization method in your app 6 | accountKitUserId: String @isUnique 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/accountkit-authentication/app-id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/accountkit-authentication/app-id.png -------------------------------------------------------------------------------- /outdated/auth/accountkit-authentication/login_success.php: -------------------------------------------------------------------------------- 1 | '; 4 | $secret = ''; 5 | $version = 'v1.1'; 6 | 7 | // Method to send Get request to url 8 | function doCurl($url) { 9 | $ch = curl_init(); 10 | curl_setopt($ch, CURLOPT_URL, $url); 11 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 12 | $data = json_decode(curl_exec($ch), true); 13 | curl_close($ch); 14 | return $data; 15 | } 16 | 17 | // Exchange authorization code for access token 18 | $token_exchange_url = 'https://graph.accountkit.com/'.$version.'/access_token?'. 19 | 'grant_type=authorization_code'. 20 | '&code='.$_POST['code']. 21 | "&access_token=AA|$app_id|$secret"; 22 | $data = doCurl($token_exchange_url); 23 | $user_id = $data['id']; 24 | $user_access_token = $data['access_token']; 25 | $refresh_interval = $data['token_refresh_interval_sec']; 26 | 27 | // call Graphcool authenticateAccountKitUser mutation with $user_access_token 28 | 29 | echo '
'.$user_access_token.'
'; 30 | ?> -------------------------------------------------------------------------------- /outdated/auth/accountkit-authentication/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateAccountKitUserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateAccountKitUser(accountKitToken: String!): AuthenticateAccountKitUserPayload 7 | } -------------------------------------------------------------------------------- /outdated/auth/accountkit-authentication/web-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/accountkit-authentication/web-settings.png -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/advanced-settings-grant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/advanced-settings-grant.png -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/advanced-settings-oauth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/advanced-settings-oauth.png -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/auth0-credentials.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/auth0-credentials.png -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/create-user.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/create-user.gif -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/new-client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/new-client.png -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/new-schema-extension.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/new-schema-extension.gif -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/assets/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-authentication/assets/settings.png -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/auth0-authentication.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: ID! @isUnique 3 | 4 | # Must be unique 5 | # Make it required if Auth0 is the only authorization method in your app 6 | auth0UserId: String @isUnique 7 | 8 | # These are some example properties that we read from Auth0 9 | # They are optional because Auth0 might not have the information 10 | name: String 11 | email: String 12 | emailVerified: Boolean 13 | givenName: String 14 | familyName: String 15 | picture: String 16 | } 17 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/aws-lambda/.gitignore: -------------------------------------------------------------------------------- 1 | # package directories 2 | node_modules 3 | jspm_packages 4 | 5 | # Serverless directories 6 | .serverless 7 | 8 | # environment settings 9 | env.yml 10 | env-*.yml -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/aws-lambda/env-dev.yml.template: -------------------------------------------------------------------------------- 1 | # insert your settings and rename this file to env-dev.yml 2 | # env variables for DEV stage environment 3 | 4 | AUTH0_DOMAIN: 5 | AUTH0_CLIENT_ID: -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/aws-lambda/handler.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const awsServerlessExpress = require('aws-serverless-express') 4 | const app = require('./app') 5 | 6 | const server = awsServerlessExpress.createServer(app) 7 | 8 | module.exports.auth0Authentication = (event, context) => awsServerlessExpress.proxy(server, event, context); 9 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/aws-lambda/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth0-authentication", 3 | "version": "1.0.0-alpha1", 4 | "description": "Serverless functions for Auth0 authentication", 5 | "main": "handler.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Petr Vlcek, petr.vlcek@gmail.com", 10 | "license": "MIT", 11 | "dependencies": { 12 | "aws-serverless-express": "^3.0.2", 13 | "body-parser": "^1.17.2", 14 | "cors": "^2.8.3", 15 | "express": "^4.15.3", 16 | "express-jwt": "^5.3.0", 17 | "graphcool-lib": "^0.0.3", 18 | "isomorphic-fetch": "^2.2.1", 19 | "jwks-rsa": "^1.2.0", 20 | "serverless-offline": "^3.15.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/aws-lambda/serverless.yml: -------------------------------------------------------------------------------- 1 | # Welcome to serverless. Read the docs 2 | # https://serverless.com/framework/docs/ 3 | 4 | # Serverless.yml is the configuration the CLI 5 | # uses to deploy your code to your provider of choice 6 | 7 | # The `service` block is the name of the service 8 | service: auth0-authentication 9 | 10 | # The `provider` block defines where your service will be deployed 11 | provider: 12 | name: aws 13 | runtime: nodejs6.10 14 | memorySize: 128 15 | 16 | # set AWS region according to your preference 17 | region: eu-central-1 18 | 19 | # deployment stage 20 | stage: dev 21 | 22 | # AWS credentials profile that will be used for deployment (see http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html for more info) 23 | profile: serverless 24 | 25 | # environment settings in env-*.yml files 26 | environment: ${file(env-${self:custom.stage}.yml)} 27 | 28 | plugins: 29 | - serverless-offline 30 | 31 | custom: 32 | stage: "${opt:stage, self:provider.stage}" 33 | 34 | # The `functions` block defines what code to deploy 35 | functions: 36 | auth0Authentication: 37 | handler: handler.auth0Authentication 38 | # The `events` block defines how to trigger the handler.auth0Authentication code 39 | events: 40 | - http: 41 | path: authenticate 42 | method: post 43 | cors: true 44 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/managed/README.md: -------------------------------------------------------------------------------- 1 | # Auth0 authentication 2 | 3 | > **Attention**: This module is not yet ready for production! 4 | 5 | Things to fix: 6 | 7 | - [ ] Remove logs 8 | - [ ] Don't return auth token if `createAuth0User` mutation failed 9 | - [ ] Validate JWT that's returned from Auth0 (https://github.com/auth0/node-jsonwebtoken) -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/managed/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | functions: 5 | authenticate: 6 | handler: 7 | code: 8 | src: ./src/authenticate.js 9 | type: resolver 10 | schema: ./src/authenticate.graphql 11 | 12 | rootTokens: 13 | - authenticate 14 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/managed/src/authenticate.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateAuth0UserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateAuth0User(idToken: String!, accessToken: String!): AuthenticateAuth0UserPayload 7 | } -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/managed/types.graphql: -------------------------------------------------------------------------------- 1 | # This file contains the GraphQL Types 2 | 3 | # All types need to have the three fields id, updatedAt and createdAt like this: 4 | 5 | type Auth0User implements Node { 6 | id: ID! @isUnique 7 | createdAt: DateTime! 8 | updatedAt: DateTime! 9 | 10 | # Must be unique 11 | # Make it required if Auth0 is the only authorization method in your app 12 | auth0UserId: String @isUnique 13 | 14 | # These are some example properties that we read from Auth0 15 | # They are optional because Auth0 might not have the information 16 | name: String 17 | email: String 18 | emailVerified: Boolean 19 | givenName: String 20 | familyName: String 21 | picture: String 22 | } 23 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/webtask/auth0-authentication.js.secrets: -------------------------------------------------------------------------------- 1 | AUTH0_DOMAIN= 2 | AUTH0_CLIENT_ID= -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/functions/webtask/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.0.3" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/login-callback.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Graphcool Auth0 example 5 | 6 | 7 | 8 | 9 | 10 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Graphcool Auth0 example 5 | 6 | 7 | 8 | 9 | 10 | 11 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /outdated/auth/auth0-authentication/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateAuth0UserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateAuth0User(idToken: String!, accessToken: String!): AuthenticateAuth0UserPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/advanced-settings-grant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/advanced-settings-grant.png -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/advanced-settings-oauth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/advanced-settings-oauth.png -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/auth0-credentials.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/auth0-credentials.png -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/create-user.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/create-user.gif -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/new-client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/new-client.png -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/new-schema-extension.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/new-schema-extension.gif -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/assets/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/auth0-database-authentication/assets/settings.png -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/auth0-authentication.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: ID! 3 | 4 | # Must be unique 5 | # Make it required if Auth0 is the only authorization method in your app 6 | auth0UserId: String @isUnique 7 | 8 | # These are some example properties that we read from Auth0 9 | # They are optional because Auth0 might not have the information 10 | name: String 11 | email: String 12 | emailVerified: Boolean 13 | givenName: String 14 | familyName: String 15 | picture: String 16 | } 17 | -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/aws-lambda/.gitignore: -------------------------------------------------------------------------------- 1 | # package directories 2 | node_modules 3 | jspm_packages 4 | 5 | # Serverless directories 6 | .serverless 7 | 8 | # environment settings 9 | env.yml 10 | env-*.yml -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/aws-lambda/env-dev.yml.template: -------------------------------------------------------------------------------- 1 | # insert your settings and rename this file to env-dev.yml 2 | # env variables for DEV stage environment 3 | 4 | AUTH0_DOMAIN: 5 | AUTH0_CLIENT_ID: -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/aws-lambda/handler.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const awsServerlessExpress = require('aws-serverless-express') 4 | const app = require('./app') 5 | 6 | const server = awsServerlessExpress.createServer(app) 7 | 8 | module.exports.auth0Authentication = (event, context) => awsServerlessExpress.proxy(server, event, context); 9 | -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/aws-lambda/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth0-authentication", 3 | "version": "1.0.0-alpha1", 4 | "description": "Serverless functions for Auth0 authentication", 5 | "main": "handler.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Petr Vlcek, petr.vlcek@gmail.com", 10 | "license": "MIT", 11 | "dependencies": { 12 | "aws-serverless-express": "^3.0.2", 13 | "body-parser": "^1.17.2", 14 | "cors": "^2.8.3", 15 | "express": "^4.15.3", 16 | "express-jwt": "^5.3.0", 17 | "graphcool-lib": "^0.0.3", 18 | "isomorphic-fetch": "^2.2.1", 19 | "jwks-rsa": "^1.2.0", 20 | "serverless-offline": "^3.15.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/aws-lambda/serverless.yml: -------------------------------------------------------------------------------- 1 | # Welcome to serverless. Read the docs 2 | # https://serverless.com/framework/docs/ 3 | 4 | # Serverless.yml is the configuration the CLI 5 | # uses to deploy your code to your provider of choice 6 | 7 | # The `service` block is the name of the service 8 | service: auth0-authentication 9 | 10 | # The `provider` block defines where your service will be deployed 11 | provider: 12 | name: aws 13 | runtime: nodejs6.10 14 | memorySize: 128 15 | 16 | # set AWS region according to your preference 17 | region: eu-central-1 18 | 19 | # deployment stage 20 | stage: dev 21 | 22 | # AWS credentials profile that will be used for deployment (see http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html for more info) 23 | profile: serverless 24 | 25 | # environment settings in env-*.yml files 26 | environment: ${file(env-${self:custom.stage}.yml)} 27 | 28 | plugins: 29 | - serverless-offline 30 | 31 | custom: 32 | stage: "${opt:stage, self:provider.stage}" 33 | 34 | # The `functions` block defines what code to deploy 35 | functions: 36 | auth0Authentication: 37 | handler: handler.auth0Authentication 38 | # The `events` block defines how to trigger the handler.auth0Authentication code 39 | events: 40 | - http: 41 | path: authenticate 42 | method: post 43 | cors: true 44 | -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/webtask/auth0-authentication.js.secrets: -------------------------------------------------------------------------------- 1 | AUTH0_DOMAIN= 2 | AUTH0_CLIENT_ID= -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/functions/webtask/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.0.3" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /outdated/auth/auth0-database-authentication/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateAuth0UserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | # This mutation can be extended to also accept optional create parameters 7 | # when creating a user in GraphCool for the first time - when the 8 | # situation calls for it. 9 | authenticateAuth0User(idToken: String!, accessToken: String!): AuthenticateAuth0UserPayload 10 | } 11 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/email-user-management.graphql: -------------------------------------------------------------------------------- 1 | # This schema is used for all included functions 2 | 3 | type User { 4 | id: ID! 5 | 6 | # Must be unique 7 | # Make it required if email is the only authorization method in your app 8 | email: String @isUnique 9 | password: String 10 | 11 | # only needed for advanced signup workflow: 12 | confirmToken: String 13 | confirmExpires: DateTime 14 | confirmed: Boolean! @defaultValue(value: false) 15 | } 16 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/authenticate/README.md: -------------------------------------------------------------------------------- 1 | # authenticate 2 | 3 | Authenticate users in your app using email and password and receive a token in return. 4 | 5 | ## Authentication flow in app 6 | 7 | 1. Your app calls the Graphcool mutation `authenticateEmailUser(email: String!, password: String!)` 8 | 2. If no user exists yet that corresponds to the passed `email`, or the `password` does not match, an error will be returned 9 | 3. If a user with the passed `email` exists and the `password` matches, the mutation returns a valid token for the user 10 | 4. Your app stores the token and uses it in its `Authorization` header for all further requests to Graphcool 11 | 12 | ## Setup the Authentication Function 13 | 14 | * Create a new Schema Extension Function and paste the schema from `schema-extension.graphql` and code from `authenticate.js`. 15 | * add a PAT to the project *called the same as your function*. The token can be obtained from the Authentication tab in the project settings. 16 | 17 | ## Test the Code 18 | 19 | First, you need to create a new user with the `signup` function. Then, go to the Graphcool Playground: 20 | 21 | ```sh 22 | graphcool playground 23 | ``` 24 | 25 | and run this mutation to authenticate as that user: 26 | 27 | ```graphql 28 | mutation { 29 | # replace __EMAIL__ and __PASSWORD__ 30 | authenticateEmailUser(email: "__EMAIL__", password: "__PASSWORD__") { 31 | token 32 | } 33 | } 34 | ``` 35 | 36 | If the email/password combo are valid you should see that it returns a token. The returned token can be used to authenticate requests to your Graphcool API as that user. 37 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/authenticate/authenticate.js: -------------------------------------------------------------------------------- 1 | const fromEvent = require('graphcool-lib').fromEvent 2 | const bcrypt = require('bcrypt') 3 | 4 | module.exports = function(event) { 5 | const email = event.data.email 6 | const password = event.data.password 7 | const graphcool = fromEvent(event) 8 | const api = graphcool.api('simple/v1') 9 | 10 | function getGraphcoolUser(email) { 11 | return api.request(` 12 | query { 13 | User(email: "${email}"){ 14 | id 15 | password 16 | } 17 | }`) 18 | .then((userQueryResult) => { 19 | if (userQueryResult.error) { 20 | return Promise.reject(userQueryResult.error) 21 | } else { 22 | return userQueryResult.User 23 | } 24 | }) 25 | } 26 | 27 | function generateGraphcoolToken(graphcoolUserId) { 28 | return graphcool.generateAuthToken(graphcoolUserId, 'User') 29 | } 30 | 31 | return getGraphcoolUser(email) 32 | .then((graphcoolUser) => { 33 | if (graphcoolUser === null) { 34 | return Promise.reject("Invalid Credentials") //returning same generic error so user can't find out what emails are registered. 35 | } else { 36 | return bcrypt.compare(password, graphcoolUser.password) 37 | .then((res) => { 38 | if (res === true) { 39 | return graphcoolUser.id 40 | } else { 41 | return Promise.reject("Invalid Credentials") 42 | } 43 | }) 44 | } 45 | }) 46 | .then(generateGraphcoolToken) 47 | .then((token) => { 48 | return { data: { token } } 49 | }) 50 | .catch((error) => { 51 | console.log(error) 52 | 53 | // don't expose error message to client! 54 | return { error: 'An unexpected error occured.' } 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/authenticate/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateEmailUserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateEmailUser(email: String!, password: String!): AuthenticateEmailUserPayload 7 | } -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/aws-ses-email/sendPasswordResetEmail.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | User(filter: { 3 | mutation_in: [UPDATED] 4 | updatedFields_contains: "resetToken" 5 | node: { 6 | resetToken_not: "null" 7 | } 8 | }) { 9 | updatedFields 10 | node { 11 | id 12 | email 13 | resetToken 14 | firstName 15 | lastName 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/aws-ses-email/sendPasswordResetEmail.js: -------------------------------------------------------------------------------- 1 | var aws = require("aws-sdk"); 2 | 3 | var ses = new aws.SES({"accessKeyId": "__ID__", "secretAccessKey": "__SECRET__", "region": "us-west-2"}); 4 | 5 | exports.handler = (event, context, callback) => { 6 | var obj = JSON.parse(event.body) 7 | var user = obj.data.User.node 8 | var email = user.email 9 | var resetToken = user.resetToken 10 | var subject = "Reset Your Password" 11 | 12 | var eParams = { 13 | Destination: { 14 | ToAddresses: [email] 15 | }, 16 | Message: { 17 | Body: { 18 | Html: { 19 | Data: ` 20 | 21 | 22 | reset your password 23 | 24 | 25 |

Hi ${email}

26 |

Click here to reset your password.

27 | 28 | 29 | ` 30 | } 31 | }, 32 | Subject: { 33 | Data: subject 34 | } 35 | }, 36 | Source: "example@example.com", 37 | ReplyToAddresses: ["example@example.com"], 38 | ReturnPath: "example@example.com" 39 | }; 40 | 41 | ses.sendEmail(eParams, function (err, data) { 42 | if (err) { 43 | console.log(err); 44 | } else { 45 | console.log(data); 46 | } 47 | }); 48 | }; -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/passwordReset.graphql: -------------------------------------------------------------------------------- 1 | type ResetPasswordPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | resetPassword(resetToken: String!, password: String!): ResetPasswordPayload 7 | } -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/postmark-email/sendPasswordResetEmail.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | User(filter: { 3 | mutation_in: [UPDATED] 4 | updatedFields_contains: "resetToken" 5 | node: { 6 | resetToken_not: "null" 7 | } 8 | }) { 9 | updatedFields 10 | node { 11 | id 12 | email 13 | resetToken 14 | firstName 15 | lastName 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/postmark-email/sendPasswordResetEmail.js: -------------------------------------------------------------------------------- 1 | var postmark = require('postmark') 2 | var client = new postmark.Client('___TOKEN____') 3 | 4 | module.exports = function (event) { 5 | const email = event.data.User.node.email 6 | const resetToken = event.data.User.node.resetToken 7 | const firstName = event.data.User.node.firstName 8 | 9 | if (!resetToken) { 10 | return 11 | } 12 | 13 | client.sendEmailWithTemplate({ 14 | 'From': 'mike@example.com', 15 | 'TemplateId': 2508781, 16 | 'To': email, 17 | 'TemplateModel': { 18 | 'firstName': firstName, 19 | 'action_url': `http://localhost:3000/reset/${resetToken}`, 20 | 'login_url': 'http://www.example.com/user', 21 | 'username': email, 22 | 'support_email': 'info@example.com', 23 | 'live_chat_url': 'testchat@example.com', 24 | 'help_url': 'http://www.example.com' 25 | } 26 | }, function (error, result) { 27 | if (error) { 28 | return console.log('error ' + error.message) 29 | } 30 | return console.log('Sent via postmark' + result) 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/sendgrid-email/sendPasswordResetEmail.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | User(filter: { 3 | mutation_in: [UPDATED] 4 | updatedFields_contains: "resetToken" 5 | node: { 6 | resetToken_not: "null" 7 | } 8 | }) { 9 | updatedFields 10 | node { 11 | id 12 | email 13 | resetToken 14 | firstName 15 | lastName 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/sendgrid-email/sendPasswordResetEmail.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | module.exports = (event) => { 3 | const { id, email, resetToken, firstName, lastName } = event.data.User.node 4 | 5 | if (!resetToken) { 6 | return null 7 | } 8 | 9 | let helper = require('sendgrid').mail 10 | const fromEmail = new helper.Email('me@example.com', 'Joe Shmoe') 11 | const subject = 'Reset your password' 12 | const htmlEmail = 13 | ` 14 | 15 | reset your password 16 | 17 | 18 |

Hi -firstname-,

19 |

Click here to reset your password.

20 | 21 | ` 22 | const content = new helper.Content('text/html', htmlEmail) 23 | 24 | let mail = new helper.Mail() 25 | mail.setFrom(fromEmail) 26 | mail.setSubject(subject) 27 | 28 | let personalization = new helper.Personalization() 29 | const toEmail = new helper.Email(email, firstName + ' ' + lastName) 30 | personalization.addTo(toEmail) 31 | let substitution = new helper.Substitution('-firstname-', firstName) 32 | personalization.addSubstitution(substitution) 33 | mail.addPersonalization(personalization) 34 | 35 | mail.addContent(content) 36 | 37 | let sg = require('sendgrid')(___SENDGRID_API_KEY___) 38 | 39 | return new Promise((resolve, reject) => { 40 | let request = sg.emptyRequest() 41 | request.body = mail.toJSON() 42 | request.method = 'POST' 43 | request.path = '/v3/mail/send' 44 | sg.API(request, (error, response) => { 45 | console.log(error) 46 | console.log(response) 47 | return error ? reject(error) : resolve(response) 48 | }) 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/reset-password/server/triggerPasswordReset.graphql: -------------------------------------------------------------------------------- 1 | type triggerPasswordResetPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | triggerPasswordReset(email: String!): triggerPasswordResetPayload 7 | } -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/1-signup-schema.graphql: -------------------------------------------------------------------------------- 1 | type SignupEmailUserPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | signupEmailUser(email: String!, password: String!): SignupEmailUserPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/2-send-schema.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | User(filter: { 3 | mutation_in: [CREATED] 4 | }) { 5 | node { 6 | email 7 | confirmToken 8 | firstName 9 | lastName 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/2-send.js: -------------------------------------------------------------------------------- 1 | "use latest" 2 | module.exports = (event) => { 3 | const { email, confirmToken, firstName, lastName } = event.data.User.node 4 | 5 | if (!confirmToken) { return null } 6 | 7 | let helper = require("sendgrid").mail 8 | const fromEmail = new helper.Email("email@mywebsite.com", "Me") 9 | const subject = "Please confirm your email" 10 | const toEmail = new helper.Email(email, firstName + " " + lastName) 11 | const content = new helper.Content("text/html", "Click here to confirm your email.") 12 | let mail = new helper.Mail(fromEmail, subject, toEmail, content) 13 | 14 | mail.personalizations[0].addSubstitution(new helper.Substitution("-firstname-", firstName)) 15 | mail.personalizations[0].addSubstitution(new helper.Substitution("-message-", "Dear " + firstName + ",

Please click the link below to confirm your email address. If you require further assistance, contact us anytime by replying to this email.")) 16 | 17 | mail.setTemplateId("__TEMPLATE_ID__") 18 | 19 | const asm = new helper.Asm(2911, [2913]) 20 | mail.setAsm(asm) 21 | 22 | let sg = require("sendgrid")("__SENDGRID_API__") 23 | 24 | return new Promise((resolve, reject) => { 25 | let request = sg.emptyRequest() 26 | request.body = mail.toJSON() 27 | request.method = "POST" 28 | request.path = "/v3/mail/send" 29 | sg.API(request, (error, response) => { 30 | console.log(error) 31 | console.log(response) 32 | return error ? reject(error) : resolve(response) 33 | }) 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/3-confirm-schema.graphql: -------------------------------------------------------------------------------- 1 | type ConfirmEmailPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | confirmEmail(confirmToken: String!): ConfirmEmailPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/3-confirm.js: -------------------------------------------------------------------------------- 1 | const fromEvent = require("graphcool-lib").fromEvent 2 | 3 | module.exports = function (event) { 4 | const confirmToken = event.data.confirmToken 5 | const graphcool = fromEvent(event) 6 | const api = graphcool.api("simple/v1") 7 | 8 | function getUserWithToken(confirmToken) { 9 | return api.request(` 10 | query { 11 | User(confirmToken: "${confirmToken}") { 12 | id 13 | } 14 | }`) 15 | .then(userQueryResult => { 16 | if (userQueryResult.error) { 17 | return Promise.reject(userQueryResult.error) 18 | } else if (!userQueryResult.User) { 19 | return Promise.reject("Not a valid token") 20 | } 21 | return userQueryResult.User.id 22 | }) 23 | } 24 | 25 | function confirmUser(userId) { 26 | return api.request(` 27 | mutation { 28 | updateUser( 29 | id: "${userId}", 30 | confirmed: true, 31 | confirmToken: null, 32 | confirmExpires: null 33 | ) { 34 | id 35 | } 36 | }`) 37 | .then(userMutationResult => (userMutationResult.updateUser.id)) 38 | } 39 | 40 | return getUserWithToken(confirmToken) 41 | .then(graphcoolUser => { 42 | console.log(graphcoolUser) 43 | const userId = graphcoolUser 44 | if (graphcoolUser === null) { 45 | return Promise.reject("No such token.") 46 | } else if (new Date() > new Date(graphcoolUser.confirmExpires)) { 47 | return Promise.reject("Token expired.") 48 | } 49 | return confirmUser(userId) 50 | .then(id => ({ data: { id } })) 51 | .catch(error => ({ error: error.toString() })) 52 | }) 53 | .catch(error => { 54 | return { error: error } 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/4-resend-schema.graphql: -------------------------------------------------------------------------------- 1 | type ResendConfirmationPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | resendConfirmation(email: String!): ResendConfirmationPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/4-resend.js: -------------------------------------------------------------------------------- 1 | const fromEvent = require("graphcool-lib").fromEvent 2 | const crypto = require("crypto") 3 | 4 | module.exports = function (event) { 5 | const email = event.data.email 6 | 7 | const graphcool = fromEvent(event) 8 | const api = graphcool.api("simple/v1") 9 | 10 | function getGraphcoolUser(email) { 11 | return api.request(` 12 | query { 13 | User(email: "${email}") { 14 | id 15 | } 16 | }`) 17 | .then(userQueryResult => { 18 | if (userQueryResult.error) { 19 | return Promise.reject(userQueryResult.error) 20 | } 21 | return userQueryResult.User 22 | }) 23 | } 24 | 25 | function generateToken() { 26 | return crypto.randomBytes(20).toString("hex") 27 | } 28 | 29 | function generateExpiration() { 30 | const now = new Date() 31 | return new Date(now.getTime() + 3600000).toISOString() 32 | } 33 | 34 | function updateGraphcoolUser(userId) { 35 | return api.request(` 36 | mutation { 37 | updateUser( 38 | id: "${userId}", 39 | confirmToken: "${generateToken()}", 40 | confirmExpires: "${generateExpiration()}" 41 | ) { 42 | id 43 | } 44 | }`) 45 | .then(userMutationResult => { 46 | return userMutationResult.updateUser.id 47 | }) 48 | } 49 | 50 | return getGraphcoolUser(email) 51 | .then(graphcoolUser => { 52 | return updateGraphcoolUser(graphcoolUser.id) 53 | }) 54 | .then(id => { 55 | return { data: { id } } 56 | }) 57 | .catch(error => { 58 | return { error: error.toString() } 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/5-send-schema.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | User(filter: { 3 | mutation_in: [UPDATED] 4 | updatedFields_contains: "confirmToken" 5 | node: { 6 | confirmToken_not: "null" 7 | } 8 | }) { 9 | updatedFields 10 | node { 11 | email 12 | confirmToken 13 | firstName 14 | lastName 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/signup/5-send.js: -------------------------------------------------------------------------------- 1 | // Same as file `2-send.js` 2 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/update-email/README.md: -------------------------------------------------------------------------------- 1 | # update-email 2 | 3 | Update the email for users in your app who login using email and password. 4 | 5 | ## Update email flow in app 6 | 7 | 1. Your app calls the Graphcool mutation `updateEmail(email: String!, password: String!, newEmail: String!)` 8 | 2. If `newEmail` passed is not a valid format, an error is returned 9 | 3. If a user with the passed `email` and `password` combination is not found, an error is returned 10 | 4. If a user with the passed `email` exists and the `password` matches, the user's `email` field is updated to the new email 11 | 5. The mutation returns the id and new email of the updated user 12 | 13 | ## Setup the Email Update Function 14 | 15 | * Create a new Schema Extension Function and paste the schema from `schema-extension.graphql` and code from `update-email.js`. 16 | * add a PAT to the project *called the same as your function*. The token can be obtained from the Authentication tab in the project settings. 17 | 18 | ## Test the Code 19 | 20 | First, you need to create a new user with the `signup` function. Then, go to the Graphcool Playground: 21 | 22 | ```sh 23 | graphcool playground 24 | ``` 25 | 26 | Run this mutation to change a user's email: 27 | 28 | ```graphql 29 | mutation { 30 | # replace __EMAIL__ , __NEW_EMAIL__ , and __PASSWORD__ 31 | updateEmail(email: "__EMAIL__", password: "__PASSWORD__", newEmail: "__NEW_EMAIL__") { 32 | id 33 | email 34 | } 35 | } 36 | ``` 37 | 38 | If the email/password combo are valid, and the newEmail is a valid format, you should see that it updates the user's email field and returns the user's id and new email. 39 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/update-email/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type UpdateEmailPayload { 2 | id: ID! 3 | email: String! 4 | } 5 | 6 | extend type Mutation { 7 | updateEmail(email: String!, password: String!, newEmail: String!): UpdateEmailPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/update-password/README.md: -------------------------------------------------------------------------------- 1 | # update-password 2 | 3 | Update the password for users in your app who login using email and password. 4 | 5 | ## Update password flow in app 6 | 7 | 1. Your app calls the Graphcool mutation `updatePassword(email: String!, password: String!, newPassword: String!)` 8 | 2. If a user with the email and password combination is not found, an error is returned 9 | 3. If a user with the passed `email` exists and `password` matches, the user's `password` field is updated to the new password. 10 | 4. The mutation returns the id of the updated user 11 | 12 | ## Setup the Password Update Function 13 | 14 | * Create a new Schema Extension Function and paste the schema from `schema-extension.graphql` and code from `update-password.js`. 15 | * add a PAT to the project *called the same as your function*. The token can be obtained from the Authentication tab in the project settings. 16 | 17 | ## Test the Code 18 | 19 | First, you need to create a new user with the `signup` function. Then, go to the Graphcool Playground: 20 | 21 | ```sh 22 | graphcool playground 23 | ``` 24 | 25 | Run this mutation to change a user's password: 26 | 27 | ```graphql 28 | mutation { 29 | # replace __EMAIL__ , __OLD_PASSWORD__ , and __NEW_PASSWORD__ 30 | updatePassword(email: "__EMAIL__", password: "__OLD_PASSWORD__", newPassword: "__NEW_PASSWORD__") { 31 | id 32 | } 33 | } 34 | ``` 35 | 36 | If the email/newPassword combo are valid you should see that it updates the user's password field and returns the user's id. 37 | -------------------------------------------------------------------------------- /outdated/auth/email-user-management/functions/update-password/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type UpdatePasswordPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | updatePassword(email: String!, password: String!, newPassword: String!): UpdatePasswordPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "airbnb", 4 | "plugins": ["import"] 5 | } 6 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | flow/ 7 | 8 | [options] 9 | emoji=true 10 | 11 | module.system=haste 12 | 13 | munge_underscores=true 14 | 15 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 16 | 17 | suppress_type=$FlowIssue 18 | suppress_type=$FlowFixMe 19 | suppress_type=$FixMe 20 | 21 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 22 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 23 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 24 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 25 | 26 | unsafe.enable_getters_and_setters=true 27 | 28 | [version] 29 | ^0.52.0 30 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/.gitignore: -------------------------------------------------------------------------------- 1 | # package directories 2 | node_modules 3 | jspm_packages 4 | 5 | yarn-error.log 6 | 7 | # Serverless directories 8 | .serverless 9 | 10 | # environment vars 11 | env-*.yml 12 | !env-dev.yml.EXAMPLE 13 | 14 | # 15 | .webpack -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/firebase-authentication/demo.png -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/env-dev.yml.EXAMPLE: -------------------------------------------------------------------------------- 1 | graphcoolPAT: "*********" 2 | graphcoolProjectId: "*********" 3 | 4 | # json in yaml 5 | firebaseKey: 6 | '{ 7 | "type": "service_account", 8 | "project_id": "*********", 9 | "private_key_id": "*********", 10 | "private_key": "*********", 11 | "client_email": "*********", 12 | "client_id": "*********", 13 | "auth_uri": "*********", 14 | "token_uri": "*********", 15 | "auth_provider_x509_cert_url": "*********", 16 | "client_x509_cert_url": "*********" 17 | }' -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/examples/one-page/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # VS Code 61 | .vscode/* 62 | !.vscode/settings.json 63 | !.vscode/tasks.json 64 | !.vscode/launch.json 65 | !.vscode/extensions.json 66 | 67 | # VS Code Local History extension 68 | .history 69 | 70 | # Expo 71 | .expo/ 72 | 73 | 74 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/examples/one-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "one-page", 3 | "version": "0.1.0", 4 | "description": "A one-page example of the firebase-authentication integration", 5 | "main": "index.js", 6 | "license": "Unlicense", 7 | "scripts": { 8 | "build": "webpack", 9 | "watch": "./node_modules/.bin/webpack --watch", 10 | "start": "webpack-dev-server --progress --colors" 11 | }, 12 | "dependencies": { 13 | "apollo-client": "^1.9.0", 14 | "apollo-fetch": "^0.6.0", 15 | "firebase": "^4.2.0", 16 | "graphql-tag": "^2.4.2", 17 | "isomorphic-fetch": "^2.2.1", 18 | "lodash": "^4.17.4" 19 | }, 20 | "devDependencies": { 21 | "webpack": "^3.5.1", 22 | "webpack-dev-server": "^2.7.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/examples/one-page/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | entry: "./index.js", 5 | output: { 6 | path: path.join(__dirname, "build"), 7 | filename: "bundle.js" 8 | }, 9 | devtool: "source-map", 10 | devServer: { 11 | contentBase: path.join(__dirname, "build"), 12 | historyApiFallback: true 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebase-graphcool-authentication", 3 | "version": "0.1.0", 4 | "main": "handler.js", 5 | "license": "Unlicense", 6 | "scripts": { 7 | "build": "./node_modules/.bin/webpack -p", 8 | "debug": "set SLS_DEBUG=* && serverless offline -s dev", 9 | "package": "cross-env NODE_ENV=production serverless package --stage prod --region us-east-1", 10 | "deploy-dev": "serverless deploy --funtion firebase-graphcool-authentication --stage dev --region us-east-1" **** change for your region; copy to add another stage 11 | }, 12 | "dependencies": { 13 | "babel-polyfill": "^6.23.0", 14 | "firebase-admin": "^5.1.0", 15 | "graphcool-lib": "^0.0.3", 16 | "jsonwebtoken": "^7.4.2", 17 | "lambda-proxy-response": "^2.0.0" 18 | }, 19 | "devDependencies": { 20 | "babel-cli": "^6.24.1", 21 | "babel-core": "^6.25.0", 22 | "babel-eslint": "^7.2.3", 23 | "babel-loader": "^7.1.1", 24 | "babel-plugin-transform-async-to-generator": "^6.24.1", 25 | "babel-plugin-transform-regenerator": "^6.24.1", 26 | "babel-preset-es2015": "^6.24.1", 27 | "babel-preset-flow": "^6.23.0", 28 | "cross-env": "^5.0.5", 29 | "eslint-config-airbnb": "^15.1.0", 30 | "eslint-plugin-import": "^2.7.0", 31 | "flow-bin": "^0.52.0", 32 | "json-loader": "^0.5.7", 33 | "prettier-eslint": "^6.4.2", 34 | "serverless": "^1.19.0", 35 | "serverless-offline": "^3.15.3", 36 | "serverless-webpack": "^2.2.0", 37 | "webpack": "^3.4.1", 38 | "webpack-node-externals": "^1.6.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/schema-extension.sdl: -------------------------------------------------------------------------------- 1 | type CustomTokenPayload { 2 | wrappedToken: String! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateFirebaseUser(firebaseIdToken: String!): CustomTokenPayload 7 | } -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/serverless.yml: -------------------------------------------------------------------------------- 1 | service: firebase-graphcool-authentication 2 | 3 | provider: 4 | name: aws 5 | runtime: nodejs6.10 6 | 7 | environment: ${file(env-${self:custom.stage}.yml)} 8 | 9 | plugins: 10 | - serverless-webpack 11 | - serverless-offline 12 | 13 | custom: 14 | stage: "${opt:stage, self:provider.stage}" 15 | webpackIncludeModules: true 16 | 17 | package: 18 | exclude: 19 | - .babelrc 20 | - .eslintrc 21 | - .flowconfig 22 | - .vscode/** 23 | - yarn.lock 24 | - yarn-error.log 25 | - env-*.yml 26 | - webpack.config.js 27 | - schema-extension.sdl 28 | 29 | functions: 30 | firebaseAuthentication: 31 | handler: src/handler.firebaseAuthentication 32 | memorySize: 128 33 | events: 34 | - http: 35 | path: authenticate 36 | method: post 37 | cors: true -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/src/handler.js: -------------------------------------------------------------------------------- 1 | import { AuthenticateFirebaseToken, Response } from "./firebase-auth"; 2 | import * as admin from "firebase-admin"; 3 | 4 | const serviceAccount = JSON.parse(process.env.firebaseKey); 5 | if (admin.apps.length < 1) { 6 | admin.initializeApp({ 7 | credential: admin.credential.cert(serviceAccount), 8 | databaseURL: process.env.databaseURL 9 | }); 10 | } 11 | 12 | export const firebaseAuthentication = (event, context, callback) => { 13 | return AuthenticateFirebaseToken(event) 14 | .then(res => { 15 | return callback(null, res); 16 | }) 17 | .catch(err => { 18 | return callback(err, null); 19 | }); 20 | }; 21 | -------------------------------------------------------------------------------- /outdated/auth/firebase-authentication/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const webpack = require("webpack"); 3 | const nodeExternals = require("webpack-node-externals"); 4 | 5 | module.exports = { 6 | entry: ["babel-polyfill", path.join(__dirname, "src", "handler.js")], 7 | output: { 8 | path: path.join(__dirname, ".webpack"), 9 | library: "firebase-graphcool-authenticator", 10 | libraryTarget: "commonjs2", 11 | filename: "src/handler.js" 12 | }, 13 | plugins: [ 14 | new webpack.DefinePlugin({ 15 | "process.env.NODE_ENV": JSON.stringify("production") 16 | }) 17 | ], 18 | target: "node", 19 | externals: [nodeExternals()], 20 | module: { 21 | rules: [ 22 | { 23 | test: /\.js$/, 24 | include: [path.join(__dirname, "src")], 25 | exclude: /node_modules/, 26 | loader: "babel-loader", 27 | query: { 28 | presets: ["es2015", "flow"], 29 | plugins: ["transform-regenerator", "transform-async-to-generator"] 30 | } 31 | }, 32 | { 33 | test: /\.json/, 34 | include: [path.join(__dirname, "src")], 35 | loader: "json-loader" 36 | } 37 | ] 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/doc/howitworks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/google-authenticator-authentication/doc/howitworks.jpg -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/doc/qr-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/auth/google-authenticator-authentication/doc/qr-sample.png -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/extensions/authenticateUser.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateUserPayload { 2 | preAuthenticated: Boolean 3 | token: String 4 | } 5 | 6 | extend type Mutation { 7 | authenticateUser(email: String!, password: String!, code: String): AuthenticateUserPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/extensions/initializeOTP.graphql: -------------------------------------------------------------------------------- 1 | type InitializeOtpPayload { 2 | success: Boolean! 3 | } 4 | 5 | extend type Mutation { 6 | initializeOTP(code: String!): InitializeOtpPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/extensions/registerOTP.graphql: -------------------------------------------------------------------------------- 1 | type RegisterOtpPayload { 2 | secret: String! 3 | uri: String! 4 | qrUrl: String! 5 | } 6 | 7 | extend type Mutation { 8 | registerOTP(secret: String): RegisterOtpPayload 9 | } 10 | -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/extensions/registerUser.graphql: -------------------------------------------------------------------------------- 1 | type RegisterUserPayload { 2 | userId: ID! 3 | } 4 | 5 | extend type Mutation { 6 | registerUser(email: String! password: String!): RegiserUserPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "otp-authentication", 3 | "version": "0.1.0", 4 | "dependencies": { 5 | "easy-pbkdf2": "^0.1.2", 6 | "express": "^4.15.3", 7 | "form-data": "^2.2.0", 8 | "graphcool-lib": "0.0.3", 9 | "node-qr-image": "0.0.1", 10 | "request": "^2.81.0", 11 | "speakeasy": "^2.0.0", 12 | "stream": "0.0.2", 13 | "thirty-two": "^1.0.2", 14 | "webtask-tools": "^3.2.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /outdated/auth/google-authenticator-authentication/schema.graphql: -------------------------------------------------------------------------------- 1 | type File implements Node { 2 | contentType: String! 3 | createdAt: DateTime! 4 | id: ID! @isUnique 5 | name: String! 6 | secret: String! @isUnique 7 | size: Int! 8 | updatedAt: DateTime! 9 | url: String! @isUnique 10 | user: User @relation(name: "QrImageForUser") 11 | } 12 | 13 | type User implements Node { 14 | createdAt: DateTime! 15 | id: ID! @isUnique 16 | email: String! @isUnique 17 | password: String! 18 | updatedAt: DateTime! 19 | otpSecret: String 20 | isOtpEnabled: Boolean! @defaultValue(value: false) 21 | qrImage: File @relation(name: "QrImageForUser") 22 | } 23 | -------------------------------------------------------------------------------- /outdated/auth/sms-authentication/confirm-code-schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateSmsUserPayload { 2 | token: String! 3 | } 4 | 5 | extend type Mutation { 6 | confirmUserSmsToken(userId: ID!, confirmCode: String!):AuthenticateSmsUserPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/sms-authentication/sms-authentication-schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type AuthenticateSmsUserPayload { 2 | userId: ID! 3 | } 4 | 5 | extend type Mutation { 6 | authenticateSmsUser(phone: String!): AuthenticateSmsUserPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/auth/sms-authentication/sms-authentication.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: ID! 3 | 4 | # Must be unique 5 | # Make this required if SMS is the only way to authorize 6 | smsToken: String @isUnique 7 | phone: String @isUnique 8 | } 9 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/address-lookup/getAddressById.graphql: -------------------------------------------------------------------------------- 1 | type AddressIdPayload { 2 | id: String 3 | street: String 4 | city: String 5 | } 6 | 7 | extend type Query { 8 | getAddressById(id: String!): AddressIdPayload 9 | } 10 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/address-lookup/getAddressById.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | const request = require('request-promise') 3 | 4 | const POSTCODE_API_KEY = '__API_KEY__' 5 | 6 | module.exports = function getAddress(event) { 7 | return new Promise((resolve, reject) => { 8 | const { id } = event.data 9 | request({ 10 | url: `https://api.postcodeapi.nu/v2/addresses/${id}`, 11 | headers: { 'X-Api-Key': POSTCODE_API_KEY } 12 | }) 13 | .then(data => { 14 | const result = JSON.parse(data) 15 | if (result) { 16 | const { city: { label: city }, street, id } = result 17 | resolve({ data: { street, city, id } }) 18 | } else { 19 | resolve({error: `No result for id '${id}'}`) 20 | } 21 | }) 22 | .catch(err => resolve({ })) 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/address-lookup/getAddressByPostcodeAndNumber.graphql: -------------------------------------------------------------------------------- 1 | type AddressByPostCodeAndNumberPayload { 2 | id: String 3 | street: String 4 | city: String 5 | } 6 | 7 | extend type Query { 8 | getAddressByPostCodeAndNumber(postcode: String! number: String!): AddressByPostCodeAndNumber 9 | } 10 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/address-lookup/getAddressByPostcodeAndNumber.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | const request = require('request-promise') 3 | 4 | const POSTCODE_API_KEY = '__API_KEY__' 5 | 6 | module.exports = function getAddress(event) { 7 | return new Promise((resolve, reject) => { 8 | const { postcode, number } = event.data 9 | request({ 10 | url: `https://api.postcodeapi.nu/v2/addresses?postcode=${postcode}&number=${number}`, 11 | headers: { 'X-Api-Key': POSTCODE_API_KEY } 12 | }) 13 | .then(data => { 14 | const result = JSON.parse(data) 15 | if (result._embedded.addresses.length) { 16 | const { city: { label: city }, street, id } = result._embedded.addresses[0] 17 | resolve({ data: { street, city, id } }) 18 | } else { 19 | resolve({error: `No result for postcode '${postcode}' and number '${number}'`}) 20 | } 21 | }) 22 | .catch(err => resolve({ })) 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/google-geocoding/README.md: -------------------------------------------------------------------------------- 1 | # google-geocoding 2 | 3 | Fetch missing geo-data for an address with Graphcool Functions and the help of [the Google Geocoding API](https://developers.google.com/maps/documentation/geocoding/intro) ⚡️ 4 | 5 | ## Setup the Google Geocoding 6 | 7 | * Create a new function as part of the **`TRANSFORM_ARGUMENT` step of the Request Pipeline** with **the trigger `Location is created`**. Paste the code from `google-geocoding.js`. 8 | 9 | * To use the Google Maps Geocoding API, [**you need to generate an API key**](https://developers.google.com/maps/documentation/geocoding/get-api-key) and replace the `__GOOGLE_API_KEY__` in the function code. 10 | 11 | Now this function will run whenever a location is created. It will ping Google with an address and get back the missing location information. 12 | 13 | The response will then be merged with the location information that was entered in the mutation before the record will be saved. 14 | 15 | ## Test the Code 16 | 17 | Go to the Graphcool Playground: 18 | 19 | ```sh 20 | graphcool playground 21 | ``` 22 | 23 | Run this mutation to create a new location and query its geolocation details: 24 | 25 | ```graphql 26 | mutation testGoogleGeocoding { 27 | createLocation( 28 | street: "221B Baker St", 29 | country: "London" 30 | ) { 31 | id 32 | street 33 | area 34 | city 35 | country 36 | lat 37 | lng 38 | } 39 | } 40 | ``` 41 | 42 | The response should be the full address and coordinates of Sherlock Holmes' home. 🤓 43 | 44 | ## Contributions 45 | 46 | Thanks so much [@kuldarkalvik](https://github.com/kuldarkalvik) for contributing this example! :tada: 47 | 48 | ![](http://i.imgur.com/5RHR6Ku.png) 49 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/google-geocoding/google-geocoding.graphql: -------------------------------------------------------------------------------- 1 | type Location { 2 | area: String 3 | city: String 4 | country: String 5 | createdAt: DateTime! 6 | id: ID! 7 | lat: Float 8 | lng: Float 9 | street: String! 10 | updatedAt: DateTime! 11 | } -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-city-and-country.graphql: -------------------------------------------------------------------------------- 1 | type GetDailyForecastByCityAndCountryPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getDailyForecastByCityAndCountry(city: String!, country: String!, count: Int!): GetDailyForecastByCityAndCountryPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-city-and-country.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/forecast/daily' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { city, country, count } = event.data 12 | 13 | const endpoint = `${api}?q=${urlencode(city)},${country}&cnt=${count}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-city.graphql: -------------------------------------------------------------------------------- 1 | type GetDailyForecastByCityPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getDailyForecastByCity(city: String!): GetDailyForecastByCityPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-city.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/forecast/daily' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { city, count } = event.data 12 | 13 | const endpoint = `${api}?q=${urlencode(city)}&cnt=${count}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-cityid.graphql: -------------------------------------------------------------------------------- 1 | type GetDailyForecastByCityIdPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getDailyForecastByCityId(cityId: Int!): GetDailyForecastByCityIdPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-cityid.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast/daily' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { cityId, count } = event.data 11 | 12 | const endpoint = `${api}?id=${cityId}&cnt=${count}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-coords.graphql: -------------------------------------------------------------------------------- 1 | type GetDailyForecastByCoordinatesPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getDailyForecastByCoordinates(lat: Float!, lon: Float!): GetDailyForecastByCoordinatesPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-coords.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast/daily' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { lat, lon, count } = event.data 11 | 12 | const endpoint = `${api}?lat=${lat}&lon=${lon}&cnt=${count}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-zipcode-and-country.graphql: -------------------------------------------------------------------------------- 1 | type GetDailyForecastByZipcodeAndCountryPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getDailyForecastByZipcodeAndCountry(zipcode: String!, country: String!): GetDailyForecastByZipcodeAndCountryPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-zipcode-and-country.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast/daily' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { zip, country, count } = event.data 11 | 12 | const endpoint = `${api}?zip=${zip},${country}&cnt=${count}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-zipcode.graphql: -------------------------------------------------------------------------------- 1 | type GetDailyForecastByZipcodePayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getDailyForecastByZipcode(zipcode: String!): GetDailyForecastByZipcodePayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/16-day-daily-forecast/get-daily-forecast-by-zipcode.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast/daily' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { zip, count } = event.data 11 | 12 | const endpoint = `${api}?zip=${zip}&cnt=${count}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-city-and-country.graphql: -------------------------------------------------------------------------------- 1 | type GetForecastByCityAndCountryPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getForecastByCityAndCountry(city: String!, country: String!): GetForecastByCityAndCountryPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-city-and-country.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/forecast' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { city, country } = event.data 12 | 13 | const endpoint = `${api}?q=${urlencode(city)},${country}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-city.graphql: -------------------------------------------------------------------------------- 1 | type GetForecastByCityPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getForecastByCity(city: String!): GetForecastByCityPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-city.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/forecast' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { city } = event.data 12 | 13 | const endpoint = `${api}?q=${urlencode(city)}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-cityid.graphql: -------------------------------------------------------------------------------- 1 | type GetForecastByCityIdPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getForecastByCityId(cityId: Int!): GetForecastByCityIdPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-cityid.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { cityId } = event.data 11 | 12 | const endpoint = `${api}?id=${cityId}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-coords.graphql: -------------------------------------------------------------------------------- 1 | type GetForecastByCoordinatesPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getForecastByCoordinates(lat: Float!, lon: Float!): GetForecastByCoordinatesPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-coords.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { lat, lon } = event.data 11 | 12 | const endpoint = `${api}?lat=${lat}&lon=${lon}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-zipcode-and-country.graphql: -------------------------------------------------------------------------------- 1 | type GetForecastByZipcodeAndCountryPayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getForecastByZipcodeAndCountry(zipcode: String!, country: String!): GetForecastByZipcodeAndCountryPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-zipcode-and-country.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { zip, country } = event.data 11 | 12 | const endpoint = `${api}?zip=${zip},${country}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-zipcode.graphql: -------------------------------------------------------------------------------- 1 | type GetForecastByZipcodePayload { 2 | cod: String 3 | message: Float 4 | cnt: Int 5 | city: Json 6 | list: [Json!] 7 | } 8 | 9 | extend type Query { 10 | getForecastByZipcode(zipcode: String!): GetForecastByZipcodePayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/5-day-3-hour-forecast/get-forecast-by-zipcode.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | require('isomorphic-fetch') 4 | 5 | const ACCESS_TOKEN = '__API_KEY__' 6 | const api = 'https://api.openweathermap.org/data/2.5/forecast' 7 | const units = 'metric' //or 'standard', or 'imperial' 8 | 9 | module.exports = (event) => { 10 | const { zip } = event.data 11 | 12 | const endpoint = `${api}?zip=${zip}&units=${units}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data.cod == 200) 18 | ? {data: data} 19 | : {error: data} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-bounding-box.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByBoundingBoxPayload { 2 | calctime: Float 3 | cod: String 4 | cnt: Int 5 | list: [Json!] 6 | } 7 | 8 | extend type Query { 9 | getWeatherByBoundingBox(lonLeft: Float!, latBottom: Float!, lonRight: Float!, latTop: Float!, zoom: Int!, cluster: Boolean!): GetWeatherByBoundingBoxPayload 10 | } 11 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-bounding-box.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/box' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { lonLeft, latBottom, lonRight, latTop, zoom, cluster } = event.data 12 | 13 | const endpoint = `${api}?bbox=${lonLeft},${latBottom},${lonRight},${latTop},${zoom}&cluster=${cluster ? 'yes' : 'no'}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-circle.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByCirclePayload { 2 | message: String 3 | cod: String 4 | cnt: Int 5 | list: [Json!] 6 | } 7 | 8 | extend type Query { 9 | getWeatherByCircle(lat: Float!, lon: Float!, count: Int!, cluster: Boolean!): GetWeatherByCirclePayload 10 | } 11 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-circle.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/find' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { lat, lon, count, cluster } = event.data 12 | 13 | const endpoint = `${api}?lat=${lat}&lon=${lon}&cnt=${count}&cluster=${cluster ? 'yes' : 'no'}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-city-and-country.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByCityAndCountryPayload { 2 | name: String 3 | dt: Float 4 | main: Json 5 | sys: Json 6 | wind: Json 7 | base: String 8 | owid: Int 9 | coord: Json 10 | clouds: Json 11 | rain: Json 12 | snow: Json 13 | weather: [Json] 14 | visibility: Int 15 | cod: Int 16 | } 17 | 18 | extend type Query { 19 | getWeatherByCityAndCountry(city: String!, country: String!): GetWeatherByCityAndCountryPayload 20 | } 21 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-city-and-country.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/weather' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { city, country } = event.data 12 | 13 | const endpoint = `${api}?q=${urlencode(city)},${country}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => { 18 | if (data.cod == 200) { 19 | data.owid = data.id; 20 | return {data: data} 21 | } 22 | else { 23 | return {error: data} 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-city.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByCityPayload { 2 | name: String 3 | dt: Float 4 | main: Json 5 | sys: Json 6 | wind: Json 7 | base: String 8 | owid: Int 9 | coord: Json 10 | clouds: Json 11 | rain: Json 12 | snow: Json 13 | weather: [Json] 14 | visibility: Int 15 | cod: Int 16 | } 17 | 18 | extend type Query { 19 | getWeatherByCity(city: String!): GetWeatherByCityPayload 20 | } 21 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-city.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/weather' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { city } = event.data 12 | 13 | const endpoint = `${api}?q=${city}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => { 18 | if (data.cod == 200) { 19 | data.owid = data.id; 20 | return {data: data} 21 | } 22 | else { 23 | return {error: data} 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-cityid.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByCityIdPayload { 2 | name: String 3 | dt: Float 4 | main: Json 5 | sys: Json 6 | wind: Json 7 | base: String 8 | owid: Int 9 | coord: Json 10 | clouds: Json 11 | rain: Json 12 | snow: Json 13 | weather: [Json] 14 | visibility: Int 15 | cod: Int 16 | } 17 | 18 | extend type Query { 19 | getWeatherByCityId(cityId: Int!): GetWeatherByCityIdPayload 20 | } 21 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-cityid.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/weather' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { cityId } = event.data 12 | 13 | const endpoint = `${api}?id=${cityId}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => { 18 | if (data.cod == 200) { 19 | data.owid = data.id; 20 | return {data: data} 21 | } 22 | else { 23 | return {error: data} 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-cityids.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByCityIdsPayload { 2 | cnt: Int 3 | list: [Json!] 4 | } 5 | 6 | extend type Query { 7 | getWeatherByCityIds(cityIds: [Int!]!): GetWeatherByCityIdsPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-cityids.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/group' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { cityIds } = event.data 12 | 13 | const endpoint = `${api}?id=${cityIds.join(',')}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => 18 | (data.cod == 200) 19 | ? {data: data} 20 | : {error: data} 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-coords.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByCoordinatesPayload { 2 | name: String 3 | dt: Float 4 | main: Json 5 | sys: Json 6 | wind: Json 7 | base: String 8 | owid: Int 9 | coord: Json 10 | clouds: Json 11 | rain: Json 12 | snow: Json 13 | weather: [Json] 14 | visibility: Int 15 | cod: Int 16 | } 17 | 18 | extend type Query { 19 | getWeatherByCoordinates(lat: Float!, lon: Float!): GetWeatherByCoordinatesPayload 20 | } 21 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-coords.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/weather' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { lat, lon } = event.data 12 | 13 | const endpoint = `${api}?lat=${lat}&lon=${lon}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => { 18 | if (data.cod == 200) { 19 | data.owid = data.id; 20 | return {data: data} 21 | } 22 | else { 23 | return {error: data} 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-zipcode-and-country.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByZipcodeAndCountryPayload { 2 | name: String 3 | dt: Float 4 | main: Json 5 | sys: Json 6 | wind: Json 7 | base: String 8 | owid: Int 9 | coord: Json 10 | clouds: Json 11 | rain: Json 12 | snow: Json 13 | weather: [Json] 14 | visibility: Int 15 | cod: Int 16 | } 17 | 18 | extend type Query { 19 | getWeatherByZipcodeAndCountry(zipcode: String!, country: String!): GetWeatherByZipcodeAndCountryPayload 20 | } 21 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-zipcode-and-country.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/weather' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { zip, country } = event.data 12 | 13 | const endpoint = `${api}?zip=${zip},${country}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => { 18 | if (data.cod == 200) { 19 | data.owid = data.id; 20 | return {data: data} 21 | } 22 | else { 23 | return {error: data} 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-zipcode.graphql: -------------------------------------------------------------------------------- 1 | type GetWeatherByZipcodePayload { 2 | name: String 3 | dt: Float 4 | main: Json 5 | sys: Json 6 | wind: Json 7 | base: String 8 | owid: Int 9 | coord: Json 10 | clouds: Json 11 | rain: Json 12 | snow: Json 13 | weather: [Json] 14 | visibility: Int 15 | cod: Int 16 | } 17 | 18 | extend type Query { 19 | getWeatherByZipcode(zipcode: String!): GetWeatherByZipcodePayload 20 | } 21 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/current-weather-data/get-weather-by-zipcode.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/weather' 8 | const units = 'metric' //or 'standard', or 'imperial' 9 | 10 | module.exports = (event) => { 11 | const { zip } = event.data 12 | 13 | const endpoint = `${api}?zip=${zip}&units=${units}&appid=${ACCESS_TOKEN}` 14 | 15 | return fetch(endpoint) 16 | .then(response => response.json()) 17 | .then(data => { 18 | if (data.cod == 200) { 19 | data.owid = data.id; 20 | return {data: data} 21 | } 22 | else { 23 | return {error: data} 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-current-uv.graphql: -------------------------------------------------------------------------------- 1 | type GetCurrentUVPayload { 2 | lat: Float 3 | lon: Float 4 | date_iso: String 5 | date: Int 6 | value: Float 7 | } 8 | 9 | extend type Query { 10 | getCurrentUV(lat: Float!, lon: Float!): GetCurrentUVPayload 11 | } 12 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-current-uv.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/uvi' 8 | 9 | module.exports = (event) => { 10 | const { lat, lon } = event.data 11 | 12 | const endpoint = `${api}?lat=${lat}&lon=${lon}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data) 18 | ? {data: data} 19 | : {error: "Something went wrong!"} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-uv-forecast.graphql: -------------------------------------------------------------------------------- 1 | type GetUVForecastPayload { 2 | forecast: [Json!] 3 | } 4 | 5 | extend type Query { 6 | getUVForecast(lat: Float!, lon: Float!, count: Int!): GetUVForecastPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-uv-forecast.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/uvi/forecast' 8 | 9 | module.exports = (event) => { 10 | const { lat, lon, count } = event.data 11 | 12 | const endpoint = `${api}?lat=${lat}&lon=${lon}&cnt=${count}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data) 18 | ? {data: data} 19 | : {error: "Something went wrong!"} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-uv-history-period.graphql: -------------------------------------------------------------------------------- 1 | type GetUVHistoryPeriodPayload { 2 | history: [Json!] 3 | } 4 | 5 | extend type Query { 6 | getUVHistoryPeriod(lat: Float!, lon: Float!, start: Int!, end: Int!): GetUVHistoryPeriodPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-uv-history-period.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/uvi/history' 8 | 9 | module.exports = (event) => { 10 | const { lat, lon, start, end } = event.data 11 | 12 | const endpoint = `${api}?lat=${lat}&lon=${lon}&start=${start}&end=${end}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data) 18 | ? {data: data} 19 | : {error: "Something went wrong!"} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-uv-history.graphql: -------------------------------------------------------------------------------- 1 | type GetUVHistoryPayload { 2 | history: [Json!] 3 | } 4 | 5 | extend type Query { 6 | getUVHistory(lat: Float!, lon: Float!, count: Int!): GetUVHistoryPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/directions-and-geocoding/openweathermap-api/uv-index/get-uv-history.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const urlencode = require('urlencode') 4 | require('isomorphic-fetch') 5 | 6 | const ACCESS_TOKEN = '__API_KEY__' 7 | const api = 'https://api.openweathermap.org/data/2.5/uvi/history' 8 | 9 | module.exports = (event) => { 10 | const { lat, lon, count } = event.data 11 | 12 | const endpoint = `${api}?lat=${lat}&lon=${lon}&cnt=${count}&appid=${ACCESS_TOKEN}` 13 | 14 | return fetch(endpoint) 15 | .then(response => response.json()) 16 | .then(data => 17 | (data) 18 | ? {data: data} 19 | : {error: "Something went wrong!"} 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/one-signal/README.md: -------------------------------------------------------------------------------- 1 | # one-signal 2 | 3 | Send a Push Notification to OneSignal with Graphcool Functions ⚡️ 4 | 5 | ## Getting Started 6 | 7 | ```sh 8 | npm -g install graphcool 9 | graphcool init --schema one-signal.graphql 10 | ``` 11 | 12 | ## Setup the Push Notification 13 | 14 | * Create a new **Server-Side Subscription** and insert this as the trigger + payload: 15 | 16 | ```graphql 17 | subscription { 18 | Event(filter: { 19 | mutation_in: [CREATED] 20 | }) { 21 | node { 22 | description 23 | location { 24 | lat 25 | lng 26 | } 27 | } 28 | } 29 | } 30 | ``` 31 | 32 | This will trigger the push notification whenever a new event is created. 33 | 34 | * Paste the code from `one-signal.js` as the inline function and replace **the OneSignal APP ID and APP KEY**. 35 | 36 | ## Test the Code 37 | 38 | Go to the Graphcool Playground: 39 | 40 | ```sh 41 | graphcool playground 42 | ``` 43 | 44 | Run this mutation to create a new event and location and trigger the Push Notification: 45 | 46 | ```graphql 47 | mutation testPushNotification { 48 | createEvent( 49 | description: "Join us on May 21st in Berlin for GraphQL Europe and be a part of Europe's first GraphQL conference ever!" 50 | location: { 51 | lat: 52.501107 52 | lng: 13.450851 53 | } 54 | ) { 55 | id 56 | } 57 | } 58 | ``` 59 | 60 | ![](http://i.imgur.com/5RHR6Ku.png) 61 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/one-signal/one-signal.graphql: -------------------------------------------------------------------------------- 1 | type Location { 2 | id: ID! 3 | event: Event @relation(name: "EventLocation") 4 | lat: Float! 5 | lng: Float! 6 | } 7 | 8 | type Event { 9 | id: ID! 10 | description: String! 11 | location: Location @relation(name: "EventLocation") 12 | } 13 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/one-signal/one-signal.js: -------------------------------------------------------------------------------- 1 | // replace OneSignal app id and key 2 | const APP_ID = '__ID__' 3 | const APP_KEY = '__KEY__' 4 | 5 | module.exports = function (event) { 6 | console.log(event.data) 7 | const location = event.data.location 8 | const message = { 9 | app_id: APP_ID, 10 | contents: { 11 | 'en': `New event! ${event.data.description.substr(0,20)} ...` 12 | }, 13 | filters: [ 14 | { 15 | field: 'location', 16 | radius: 25000, // 25km 17 | lat: location.latitude, 18 | long: location.longitude 19 | } 20 | ] 21 | } 22 | sendNotification(message) 23 | } 24 | 25 | const sendNotification = function(data) { 26 | const headers = { 27 | 'Content-Type': 'application/json', 28 | 'Authorization': APP_KEY 29 | } 30 | 31 | const options = { 32 | host: 'onesignal.com', 33 | port: 443, 34 | path: '/api/v1/notifications', 35 | method: 'POST', 36 | headers: headers 37 | } 38 | 39 | const https = require('https') 40 | const req = https.request(options, function(res) { 41 | res.on('data', function(data) { 42 | console.log('Response:') 43 | console.log(JSON.parse(data)) 44 | }) 45 | }) 46 | 47 | req.on('error', function(e) { 48 | console.log('ERROR:') 49 | console.log(e) 50 | }) 51 | 52 | req.write(JSON.stringify(data)) 53 | req.end() 54 | } 55 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/sendgrid-email/addtolist.js: -------------------------------------------------------------------------------- 1 | module.exports = function (event) { 2 | var sg = require('sendgrid')(__SENDGRID_SECRET_KEY__) 3 | var request = sg.emptyRequest() 4 | request.body = [{ 5 | 'email': event.data.User.node.email, 6 | 'first_name': event.data.User.node.nameFirst, 7 | 'last_name': event.data.User.node.nameLast 8 | }]; 9 | request.method = 'POST' 10 | request.path = '/v3/contactdb/recipients' 11 | return new Promise(function(resolve, reject) { 12 | sg.API(request, function (error, response) { 13 | console.log(response.body.persisted_recipients[0]) 14 | var request = sg.emptyRequest() 15 | request.method = 'POST' 16 | request.path = '/v3/contactdb/lists/___SENDGRID_LIST_ID___/recipients/' + response.body.persisted_recipients[0] 17 | sg.API(request, function (error, response) { 18 | if (error) { 19 | console.log('Error response received') 20 | reject(error) 21 | } 22 | resolve(response) 23 | }) 24 | }) 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/sendgrid-email/addtolist_es6.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | module.exports = (event) => { 3 | let sg = require("sendgrid")(___SENDGRID_API_KEY___) 4 | 5 | return new Promise((resolve, reject) => { 6 | let request = sg.emptyRequest() 7 | const { email, nameFirst: first_name, nameLast: last_name } = event.data.User.node 8 | request.body = [{ email, first_name, last_name }] 9 | request.method = "POST" 10 | request.path = "/v3/contactdb/recipients" 11 | 12 | callAPI(request).then(response => { 13 | let request = sg.emptyRequest() 14 | request.method = 'POST' 15 | request.path = '/v3/contactdb/lists/___SENDGRID_LIST_ID___/recipients/' + response.body.persisted_recipients[0] 16 | 17 | callAPI(request) 18 | .then(response => resolve(response)) 19 | .catch(error => reject(error)) 20 | }) 21 | }) 22 | } 23 | 24 | function callAPI(sg, request) { 25 | return new Promise((resolve, reject) => { 26 | sg.API(request, (error, response) => (error ? reject(error) : resolve(response))) 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/sendgrid-email/email.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/emails-and-notifications/sendgrid-email/email.jpg -------------------------------------------------------------------------------- /outdated/emails-and-notifications/sendgrid-email/email.js: -------------------------------------------------------------------------------- 1 | const mailHelper = require('sendgrid').mail 2 | const sendgrid = require('sendgrid')('__SENDGRID_SECRET_KEY__') 3 | const fromEmail = new mailHelper.Email('from@email.com') 4 | const model = 'User' // Or any model name you link this function to 5 | 6 | const title = data => `Email subject with data ${data.id}` 7 | const content = data => `Content with data ${data.id}` 8 | 9 | const generateMail = data => new mailHelper.Mail( 10 | fromEmail, 11 | title(data), 12 | new mailHelper.Email(data.email), 13 | new mailHelper.Content('text/plain', content(data)) 14 | ) 15 | 16 | const generateRequest = mail => sendgrid.emptyRequest({ 17 | method: 'POST', 18 | path: '/v3/mail/send', 19 | body: mail.toJSON() 20 | }) 21 | 22 | module.exports = event => new Promise((resolve, reject) => sendgrid.API( 23 | generateRequest(generateMail(event.data[model].node)), 24 | (error, response) => { 25 | if (error) { 26 | console.log(error) 27 | return reject(error) 28 | } 29 | resolve(response) 30 | } 31 | )) 32 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/sendgrid-email/sendgrid-email.graphql: -------------------------------------------------------------------------------- 1 | type Contacts implements Node { 2 | createdAt: DateTime! 3 | id: ID! @isUnique 4 | updatedAt: DateTime! 5 | nameFirst: String! 6 | email: String! 7 | user: User @relation(name: "UserToContactsRelation") 8 | } 9 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/slack-bot-notifications/README.md: -------------------------------------------------------------------------------- 1 | # slack-bot-notification 2 | 3 | Send a Slack notification with Graphcool Functions ⚡️ 4 | 5 | ## Getting Started 6 | 7 | ```sh 8 | npm -g install graphcool 9 | graphcool init --schema https://graphqlbin.com/instagram.graphql 10 | ``` 11 | 12 | ## Setup the Slack Bot 13 | 14 | * [Create a new Bot](https://api.slack.com/apps) for one of your Slack Teams and **copy its Webhook URL**. 15 | 16 | * Create a new **Server-Side Subscription** event and insert this as the trigger + payload: 17 | 18 | ```graphql 19 | subscription { 20 | Post(filter: { 21 | mutation_in: [CREATED] 22 | }) { 23 | node { 24 | id 25 | description 26 | imageUrl 27 | } 28 | } 29 | } 30 | ``` 31 | 32 | This will trigger the Slack notification whenever a new post is created. 33 | 34 | * Paste the code from `slack-bot-notifications.js` as the inline function and replace `__SLACK_WEBHOOK_ID__` with the URL to your bot. 35 | 36 | ## Test the Code 37 | 38 | Go to the Graphcool Playground: 39 | 40 | ```sh 41 | graphcool playground 42 | ``` 43 | 44 | Run this mutation to create a new post and trigger the Slack notification: 45 | 46 | ```graphql 47 | mutation testSlackNotification { 48 | createPost( 49 | description: "Sky of Stars" 50 | imageUrl: "https://images.unsplash.com/photo-1468956398224-6d6f66e22c35?dpr=2&auto=compress,format&fit=crop&w=991&h=656&q=80&cs=tinysrgb&crop=&bg=" 51 | ) { 52 | id 53 | } 54 | } 55 | ``` 56 | 57 | You should see a notification in your Slack channel like this: 58 | 59 | ![](./screenshot.png) 60 | 61 | ![](http://i.imgur.com/5RHR6Ku.png) 62 | -------------------------------------------------------------------------------- /outdated/emails-and-notifications/slack-bot-notifications/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/emails-and-notifications/slack-bot-notifications/screenshot.png -------------------------------------------------------------------------------- /outdated/emails-and-notifications/slack-bot-notifications/slack-bot-notifications.js: -------------------------------------------------------------------------------- 1 | var SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/__SLACK_WEBHOOK_ID__' 2 | var slack = require('slack-notify')(SLACK_WEBHOOK_URL) 3 | 4 | module.exports = function (event) { 5 | console.log('New post created:') 6 | console.log(event.data.Post.node) 7 | 8 | slack.send({ 9 | text: ('New Post:' + event.data.Post.node.imageUrl + '\n> ' + event.data.Post.node.description), 10 | unfurl_links: 1, 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /outdated/file-handling/aws-s3-signed-url/schema.graphql: -------------------------------------------------------------------------------- 1 | type SignedUrlType { 2 | fileName: String! 3 | signedUrl: String! 4 | getUrl: String! 5 | } 6 | 7 | extend type Query { 8 | SignedUrl(filePath: String!): SignedUrlType! 9 | } -------------------------------------------------------------------------------- /outdated/file-handling/cloudinary-images/README.md: -------------------------------------------------------------------------------- 1 | # cloudinary-images 2 | 3 | Upload, automatically transform an image using Cloudinary with Graphcool Functions ⚡️ 4 | 5 | ## Getting Started 6 | 7 | ```sh 8 | npm -g install graphcool 9 | graphcool init --schema cloudinary-images.graphql 10 | ``` 11 | 12 | ## Setup 13 | 14 | * Create a new **Server-Side Subscription** event and insert this as the trigger + payload: 15 | 16 | ```graphql 17 | subscription { 18 | UserAvatar(filter: { 19 | mutation_in: [UPDATED] 20 | updatedFields_contains: "imageUrl" 21 | }) { 22 | node { 23 | id 24 | file { 25 | url 26 | } 27 | user { 28 | id 29 | } 30 | } 31 | } 32 | } 33 | ``` 34 | 35 | This will trigger the Cloudinary upload and image transformation whenever a new image is uploaded. 36 | 37 | * Paste the code from `cloudinary.js` as the inline function and replace `___CLOUDINARY_NAME___`, `___CLOUDINARY_KEY___`, `___CLOUDINARY_SECRET___` with your unique Cloudinary information. Also replace your `___PROJECT_ID___` and add a `___GRAPHCOOL_PAT___` permanent authentication token. 38 | 39 | * On the front-end, implement `upload-avatar.js` (using React) and `graphql.js`. Local state will update image once transformed image from Cloudinary has been received. From there, you can add all sorts of shenanigans (such as a loading modal instead of showing the original image). 40 | 41 | ## Contributions 42 | 43 | Thanks so much [@heymartinadams](https://github.com/heymartinadams) for contributing this example! :tada: 44 | 45 | ![](http://i.imgur.com/5RHR6Ku.png) 46 | -------------------------------------------------------------------------------- /outdated/file-handling/cloudinary-images/graphql.js: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag' 2 | 3 | export const createUserAvatar = gql` 4 | mutation { 5 | createUserAvatar { 6 | id 7 | } 8 | } 9 | ` 10 | 11 | export const assignFileToUserAvatar = gql` 12 | mutation($userAvatarId: ID!, $fileId: ID!) { 13 | assignFileToUserAvatar: setUserAvatarToFileRelation(userAvatarUserAvatarId: $userAvatarId, fileFileId: $fileId) { 14 | userAvatarUserAvatar { 15 | id 16 | } 17 | fileFile { 18 | id 19 | } 20 | } 21 | } 22 | ` 23 | 24 | export const assignUserAvatarToUser = gql` 25 | mutation($userAvatarId: ID!, $userId: ID!) { 26 | assignUserAvatarToUser: setUserAvatarToUserRelation(userAvatarUserAvatarId: $userAvatarId, userUserId: $userId) { 27 | userAvatarUserAvatar { 28 | id 29 | } 30 | userUser { 31 | id 32 | } 33 | } 34 | } 35 | ` 36 | 37 | export const updateUserAvatar = gql` 38 | mutation ($userAvatarId: ID!, $imageUrl: String!) { 39 | updateUserAvatar: updateUserAvatar(id: $userAvatarId, imageUrl: $imageUrl) { 40 | id 41 | } 42 | } 43 | ` 44 | 45 | export const receiveCloudinaryUrl = gql` 46 | subscription($id: ID!) { 47 | UserAvatar(filter: { 48 | mutation_in: [UPDATED] 49 | node: { 50 | user: { 51 | id: $id 52 | }, 53 | cloudinaryUrl_not: "null" 54 | } 55 | updatedFields_contains: "cloudinaryUrl" 56 | }) { 57 | node { 58 | cloudinaryUrl 59 | } 60 | } 61 | } 62 | ` 63 | -------------------------------------------------------------------------------- /outdated/file-handling/cloudinary-images/schema.graphql: -------------------------------------------------------------------------------- 1 | type UserAvatar implements Node { 2 | cloudinaryUrl: String @isUnique 3 | createdAt: DateTime! 4 | file: File @relation(name: "UserAvatarToFileRelation") 5 | id: ID! @isUnique 6 | imageUrl: String 7 | updatedAt: DateTime! 8 | user: User @relation(name: "UserAvatarToUserRelation") 9 | } 10 | 11 | type File { 12 | id: ID! 13 | } 14 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/.gitignore: -------------------------------------------------------------------------------- 1 | *.lock 2 | node_modules 3 | *.graphcool 4 | package-lock.json 5 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/auth-file-proxy/auth-file-proxy.graphql: -------------------------------------------------------------------------------- 1 | type File { 2 | myFile: MyFile @relation(name: "FileConnection") 3 | } 4 | 5 | type MyFile { 6 | file: File @relation(name: "FileConnection") 7 | contentType: String 8 | name: String 9 | secret: String @isUnique 10 | size: Int 11 | url: String @isUnique 12 | } 13 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/auth-file-proxy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth-file-proxy", 3 | "version": "0.1.0", 4 | "description": "Comprehensive example to create a file proxy with authentication", 5 | "dependencies": { 6 | "crypto": "^0.0.3", 7 | "express": "^4.15.3", 8 | "express-bearer-token": "^2.1.0", 9 | "form-data": "^2.2.0", 10 | "moment": "^2.18.1", 11 | "graphql-request": "^1.2.0", 12 | "multiparty": "^4.1.3", 13 | "path": "^0.12.7", 14 | "request": "^2.81.0", 15 | "webtask-tools": "^3.2.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/everypixel-sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/file-handling/file-proxy/everypixel-sample.jpg -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/file-handling/file-proxy/logo.png -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "file-proxy", 3 | "version": "0.1.0", 4 | "description": "Set of examples for creating a File proxy", 5 | "dependencies": { 6 | "crypto": "^0.0.3", 7 | "express": "^4.15.3", 8 | "form-data": "^2.2.0", 9 | "graphql-request": "^1.2.0", 10 | "multiparty": "^4.1.3", 11 | "path": "^0.12.7", 12 | "request": "^2.81.0", 13 | "webtask-tools": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/schemas/everypixel-file-proxy.graphql: -------------------------------------------------------------------------------- 1 | type File { 2 | keywords: [Json!] 3 | quality: Float 4 | } 5 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/schemas/metadata-file-proxy.graphql: -------------------------------------------------------------------------------- 1 | type File { 2 | newUrl: String 3 | description: String 4 | category: String 5 | } 6 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/schemas/simple-file-proxy.graphql: -------------------------------------------------------------------------------- 1 | type File { 2 | newUrl: String 3 | } 4 | -------------------------------------------------------------------------------- /outdated/file-handling/file-proxy/small-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/file-handling/file-proxy/small-logo.png -------------------------------------------------------------------------------- /outdated/miscellaneous/generate-slug/README.md: -------------------------------------------------------------------------------- 1 | # generate-slug 2 | 3 | Generate a slug for items with Graphcool Functions ⚡️ 4 | 5 | ## Getting Started 6 | 7 | ```sh 8 | npm -g install graphcool 9 | graphcool init --schema generate-slug.graphql 10 | ``` 11 | 12 | ## Setup the Slug Generation 13 | 14 | * Create a new function as part of the **`TRANSFORM_ARGUMENT` step of the Request Pipeline** and paste the code from `generate-slug.js`. This will create a slug whenever an item is created. 15 | 16 | ## Test the Code 17 | 18 | Go to the Graphcool Playground: 19 | 20 | ```sh 21 | graphcool playground 22 | ``` 23 | 24 | Run this mutation to create a new item and query its generated slug: 25 | 26 | ```graphql 27 | mutation testSlugGeneration { 28 | createItem( 29 | name: "A new Item" 30 | ) { 31 | id 32 | name 33 | slug 34 | } 35 | } 36 | ``` 37 | 38 | You should see the generated slug `a-new-item`. 39 | 40 | ![](http://i.imgur.com/5RHR6Ku.png) 41 | -------------------------------------------------------------------------------- /outdated/miscellaneous/generate-slug/generate-slug.graphql: -------------------------------------------------------------------------------- 1 | type Item { 2 | id: ID! 3 | name: String! 4 | # we set it to optional so we can automatically generate it 5 | slug: String @isUnique 6 | } 7 | -------------------------------------------------------------------------------- /outdated/miscellaneous/generate-slug/generate-slug.js: -------------------------------------------------------------------------------- 1 | const slugify = require('slugify') 2 | 3 | module.exports = function (event) { 4 | const name = event.data.name 5 | const suffix = Math.random().toString(36).substring(8) 6 | 7 | const slugifiedName = slugify(name, { 8 | lower: true 9 | }) 10 | 11 | const slug = `${slugifiedName}-${suffix}` 12 | 13 | event.data.slug = slug 14 | 15 | return { 16 | data: event.data 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /outdated/miscellaneous/github-fetch-repo/README.md: -------------------------------------------------------------------------------- 1 | # github-fetch-repo 2 | 3 | Save Github Repo information with Graphcool Functions ⚡️ 4 | 5 | ## Getting Started 6 | 7 | ```sh 8 | npm -g install graphcool 9 | graphcool init --schema github-repo.graphql 10 | ``` 11 | 12 | ## Setup 13 | 14 | * Generate a new [GitHub API token](https://github.com/settings/tokens/new) with access to `repo`: 15 | ![](./github-token.png) 16 | 17 | * Create a new Request Pipeline function 18 | 19 | Paste the code from `github-fetch-repo.js` as an inline function at the `TRANSFORM_ARGUMENT` step when a `GithubRepo is created` and replace `__GITHUB_API_TOKEN__` with your unique Github API Token. 20 | 21 | ## Test the Code 22 | 23 | Go to the Graphcool Playground: 24 | 25 | ```sh 26 | graphcool playground 27 | ``` 28 | 29 | Run this mutation to create a new Github Repository: 30 | 31 | ```graphql 32 | mutation { 33 | createGithubRepo( 34 | repoUrl: "https://github.com/facebook/react" 35 | ) { 36 | name 37 | owner 38 | description 39 | homepageUrl 40 | repoUrl 41 | } 42 | } 43 | ``` 44 | 45 | You should receive the following response: 46 | 47 | ```json 48 | { 49 | "data": { 50 | "createGithubRepo": { 51 | "name": "react", 52 | "repoUrl": "https://github.com/facebook/react", 53 | "description": "A declarative, efficient, and flexible JavaScript library for building user interfaces.", 54 | "homepageUrl": "https://facebook.github.io/react/", 55 | "owner": "facebook" 56 | } 57 | } 58 | } 59 | ``` 60 | 61 | ## Contributions 62 | 63 | Thanks so much [@dkh215](https://github.com/dkh215) for contributing this example! :tada: 64 | 65 | ![](http://i.imgur.com/5RHR6Ku.png) 66 | -------------------------------------------------------------------------------- /outdated/miscellaneous/github-fetch-repo/github-repo.graphql: -------------------------------------------------------------------------------- 1 | type GithubRepo implements Node { 2 | createdAt: DateTime! 3 | id: ID! @isUnique 4 | name: String @isUnique 5 | updatedAt: DateTime! 6 | avatar: String 7 | changelog: String 8 | description: String 9 | homepageUrl: String 10 | issues: Int 11 | lastCommit: Json 12 | lastRelease: Json 13 | license: String 14 | owner: String 15 | primaryLanguage: Json 16 | pullRequests: Int 17 | readme: String 18 | repoUrl: String! @isUnique 19 | stars: Int 20 | } -------------------------------------------------------------------------------- /outdated/miscellaneous/github-fetch-repo/github-token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/miscellaneous/github-fetch-repo/github-token.png -------------------------------------------------------------------------------- /outdated/miscellaneous/quote-of-the-day/README.md: -------------------------------------------------------------------------------- 1 | # Schema Extensions for TheySaidSo Famous Quotes API 2 | 3 | A fun set of schema extension queries that exposes the public [TheySaidSo Famous Quotes API](https://theysaidso.com/api/) through your Graphcool endpoint. 4 | 5 | > Please follow the TheySaidSo API [attribution guidelines](https://theysaidso.com/api/) when using this API. 6 | 7 | ## Getting Started 8 | 9 | - Create Schema Extensions using the `.graphql` and `.js` files provided in this project 10 | 11 | ## Implemented queries 12 | 13 | All public TheySaidSo Quotes API endpoints are implemented. 14 | 15 | `getQuote(category: String)` - [Documentation](https://theysaidso.com/api/#qod) and [Documentation](https://theysaidso.com/api/#qodcatopt) 16 | 17 | `getQuoteCategories` - [Documentation](https://theysaidso.com/api/#qodcat) 18 | 19 | ## Contributions 20 | 21 | Thanks so much [@kbrandwijk](https://github.com/kbrandwijk) for contributing this example! :tada: 22 | -------------------------------------------------------------------------------- /outdated/miscellaneous/quote-of-the-day/get-quote-categories.graphql: -------------------------------------------------------------------------------- 1 | type GetQuoteCategoriesPayload { 2 | success: Json 3 | contents: Json 4 | } 5 | 6 | extend type Query { 7 | getQuoteCategories: GetQuoteCategoriesPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/miscellaneous/quote-of-the-day/get-quote-categories.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | module.exports = (event) => { 6 | const options = 7 | { 8 | baseUrl: 'http://quotes.rest/', 9 | uri: '/qod/categories', 10 | method: 'GET', 11 | json: true 12 | } 13 | 14 | return request(options) 15 | .then(data => { return { data: data } }) 16 | .catch(error => { return { error: error } }) 17 | } 18 | -------------------------------------------------------------------------------- /outdated/miscellaneous/quote-of-the-day/get-quote.graphql: -------------------------------------------------------------------------------- 1 | type GetQuotePayload { 2 | success: Json 3 | contents: Json 4 | } 5 | 6 | extend type Query { 7 | getQuote(category: String): GetQuotePayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/miscellaneous/quote-of-the-day/get-quote.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | module.exports = (event) => { 6 | const { category } = event.data 7 | const options = 8 | { 9 | baseUrl: 'http://quotes.rest/', 10 | uri: 'qod.json', 11 | method: 'GET', 12 | json: true 13 | } 14 | 15 | if (category) options.qs = { category: category } 16 | 17 | return request(options) 18 | .then(data => { return { data: data } }) 19 | .catch(error => { return { error: error } }) 20 | } 21 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/functions/computer-makes-move.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | GameState(filter: { 3 | mutation_in: [CREATED, UPDATED], 4 | node: { turn: Computer} 5 | }) { 6 | node { 7 | game { 8 | id 9 | level 10 | } 11 | board 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/functions/computer-makes-move.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const { fromEvent } = require('graphcool-lib') 4 | 5 | const pat = '__PAT__' 6 | const projectId = '__PROJECTID__' 7 | 8 | module.exports = (event) => { 9 | event.context = { graphcool: { pat, projectId } } 10 | const api = fromEvent(event).api('simple/v1'); 11 | 12 | const nextMove = takeNoobMove(event.data.GameState.node.board) 13 | const mutation = `mutation { 14 | createMove( 15 | gameId: "${event.data.GameState.node.game.id}", 16 | position: ${nextMove+1}, 17 | player: Computer) 18 | { id } }` 19 | 20 | // Return a Promise to wait for the mutation to complete 21 | return new Promise((resolve,reject) => { 22 | api.request(mutation) 23 | .then(data => resolve({ data: event.data })) 24 | .catch(err => resolve({ error: err})) 25 | }) 26 | } 27 | 28 | function findEmptySpots(board) 29 | { 30 | const emptySpots = [] 31 | for (var i = 0; i < board.length; i++) 32 | { 33 | if (board[i] === "") emptySpots.push(i) 34 | } 35 | return emptySpots 36 | } 37 | 38 | function takeNoobMove(board) { 39 | const available = findEmptySpots(board); 40 | var randomCell = available[Math.floor(Math.random() * available.length)]; 41 | return randomCell 42 | } 43 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/functions/create-gamestate-for-new-game.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const { fromEvent } = require('graphcool-lib') 4 | const crypto = require('crypto') 5 | 6 | const pat = '__PAT__' 7 | const projectId = '__PROJECTID__' 8 | 9 | module.exports = (event) => { 10 | event.context = { graphcool: { pat, projectId } } 11 | const api = fromEvent(event).api('simple/v1'); 12 | 13 | // Flip a coin to see who gets to go first 14 | const turn = crypto.randomBytes(1)[0] > 127 ? "User" : "Computer" 15 | 16 | // Flip another coin to determine player symbol 17 | const playerSymbol = crypto.randomBytes(1)[0] > 127 ? "X" : "O" 18 | 19 | 20 | // Mutation to create GameState for the new Game 21 | const mutation = `mutation { 22 | createGameState( 23 | gameId: "${event.data.id}", 24 | turn: ${turn}, 25 | playerSymbol: ${playerSymbol}) 26 | { id } }` 27 | 28 | // Return a Promise to wait for the mutation to complete 29 | return new Promise((resolve,reject) => { 30 | api.request(mutation) 31 | .then(data => resolve({ data: event.data })) 32 | .catch(err => resolve({ error: err})) 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/permissions/create-move.graphql: -------------------------------------------------------------------------------- 1 | query ($user_id: ID!, $input_gameId: ID!, $input_position: Int!) { 2 | SomeGameExists(filter: { 3 | AND: [ 4 | { gameState: { turn: User, status: InProgress} } 5 | { player: { id: $user_id} } 6 | { id: $input_gameId } 7 | { moves_none: { position: $input_position} } 8 | ] 9 | }) 10 | } 11 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/permissions/read-game.graphql: -------------------------------------------------------------------------------- 1 | query ($node_id: ID!, $user_id: ID!) { 2 | SomeGameExists( 3 | filter: { 4 | AND: [ 5 | {id: $node_id}, 6 | { player: { id: $user_id } } 7 | ] 8 | } 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/permissions/read-gamestate.graphql: -------------------------------------------------------------------------------- 1 | query ($node_id: ID!, $user_id: ID!) { 2 | SomeGameStateExists( 3 | filter: { 4 | id: $node_id 5 | game: { player: { id: $user_id } } 6 | } 7 | ) 8 | } 9 | -------------------------------------------------------------------------------- /outdated/miscellaneous/tictactoe-gameserver/schema.graphql: -------------------------------------------------------------------------------- 1 | type Game implements Node { 2 | createdAt: DateTime! 3 | gameState: GameState @relation(name: "GameStateOnGame") 4 | id: ID! @isUnique 5 | moves: [Move!]! @relation(name: "GameMove") 6 | player: User! @relation(name: "GameOnUser") 7 | updatedAt: DateTime! 8 | level: Level! 9 | } 10 | 11 | type GameState implements Node { 12 | board: [String!]! @defaultValue(value: "[\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"]") 13 | createdAt: DateTime! 14 | game: Game! @relation(name: "GameStateOnGame") 15 | id: ID! @isUnique 16 | playerSymbol: Symbol! 17 | status: GameStatus! @defaultValue(value: InProgress) 18 | turn: Player 19 | updatedAt: DateTime! 20 | winner: Winner 21 | } 22 | 23 | type Move implements Node { 24 | createdAt: DateTime! 25 | game: Game! @relation(name: "GameMove") 26 | id: ID! @isUnique 27 | player: Player! @defaultValue(value: User) 28 | position: Int! 29 | updatedAt: DateTime! 30 | } 31 | 32 | type User implements Node { 33 | createdAt: DateTime! 34 | games: [Game!]! @relation(name: "GameOnUser") 35 | id: ID! @isUnique 36 | #isVerified: Boolean! @defaultValue(value: false) 37 | #secret: String @isUnique 38 | updatedAt: DateTime! 39 | } 40 | 41 | enum GameStatus { 42 | InProgress 43 | Finished 44 | } 45 | 46 | enum Symbol { 47 | X 48 | O 49 | } 50 | 51 | enum Player { 52 | User 53 | Computer 54 | } 55 | 56 | enum Winner { 57 | User 58 | Computer 59 | Draw 60 | } 61 | 62 | enum Level { 63 | Noob 64 | Beginner 65 | Intermediate 66 | Master 67 | } 68 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/invoices-resource/get-user-invoices.graphql: -------------------------------------------------------------------------------- 1 | type GetUserInvoicesPayload { 2 | invoices: [Json!]! 3 | } 4 | 5 | extend type Query { 6 | getUserInvoices: GetUserInvoicesPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/invoices-resource/get-user-invoices.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const options = 10 | { 11 | auth: { 12 | user: SENDCLOUD_PUBLIC_KEY, 13 | pass: SENDCLOUD_SECRET_KEY 14 | }, 15 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 16 | uri: `/user/invoices`, 17 | method: 'GET', 18 | json: true 19 | } 20 | 21 | return request(options) 22 | .then(data => { return { data: data } }) 23 | .catch(error => { return error }) 24 | } 25 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/label-resource/get-label.graphql: -------------------------------------------------------------------------------- 1 | type GetLabelPayload { 2 | normal_printer: [String!] 3 | label_printer: String 4 | } 5 | 6 | extend type Query { 7 | getLabel(parcelId: Int!): GetLabelPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/label-resource/get-label.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { parcelId } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/labels/${parcelId}`, 19 | method: 'GET', 20 | json: true 21 | } 22 | 23 | return request(options) 24 | .then(data => { return { data: data.label } }) 25 | .catch(error => { return { error: error } }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/label-resource/get-labels.graphql: -------------------------------------------------------------------------------- 1 | type GetLabelsPayload { 2 | normal_printer: [String!] 3 | label_printer: String 4 | } 5 | 6 | extend type Query { 7 | getLabel(parcels: [Int!]!): GetLabelsPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/label-resource/get-labels.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { parcels } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/labels`, 19 | method: 'POST', 20 | body: { label: { parcels: parcels } }, 21 | json: true 22 | } 23 | 24 | return request(options) 25 | .then(data => { return { data: data.label } }) 26 | .catch(error => { return { error: error } }) 27 | } 28 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/cancel-parcel.graphql: -------------------------------------------------------------------------------- 1 | type CancelParcelPayload { 2 | status: String! 3 | message: String! 4 | } 5 | 6 | extend type Mutation { 7 | cancelParcel(parcelId: Int!): CancelParcelPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/cancel-parcel.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { parcelId } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/parcels/${parcelId}/cancel`, 19 | method: 'POST', 20 | json: true 21 | } 22 | 23 | return request(options) 24 | .then(data => { return {data: data} }) 25 | .catch(error => { return {error: error} }) 26 | } 27 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/change-parcel.graphql: -------------------------------------------------------------------------------- 1 | type ChangeParcelPayload { 2 | # More specific return format? 3 | result: Json 4 | } 5 | 6 | extend type Mutation { 7 | changeParcel(parcel: Json!): ChangeParcelPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/change-parcel.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { parcel } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/parcels`, 19 | method: 'PUT', 20 | body: parcel, 21 | json: true 22 | } 23 | 24 | return request(options) 25 | .then(data => { return { data: { result: data } } }) 26 | .catch(error => { return {error: error} }) 27 | } 28 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/create-parcel.graphql: -------------------------------------------------------------------------------- 1 | type CreateParcelPayload { 2 | # More specific return format? 3 | result: Json 4 | } 5 | 6 | extend type Mutation { 7 | createParcel(parcel: Json!): CreateParcelPayload 8 | } 9 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/create-parcel.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | const SENDCLOUD_PARTNER_ID = null 8 | 9 | module.exports = (event) => { 10 | const { parcel } = event.data 11 | 12 | const options = 13 | { 14 | auth: { 15 | user: SENDCLOUD_PUBLIC_KEY, 16 | pass: SENDCLOUD_SECRET_KEY 17 | }, 18 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 19 | uri: `/parcels`, 20 | method: 'POST', 21 | body: parcel, 22 | json: true 23 | } 24 | 25 | if (SENDCLOUD_PARTNER_ID) 26 | { 27 | options.headers = { 'Sendcloud-Partner-Id', SENDCLOUD_PARTNER_ID } 28 | } 29 | 30 | return request(options) 31 | .then(data => { return { data: { result: data } } }) 32 | .catch(error => { return { error: error } }) 33 | } 34 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/get-parcel.graphql: -------------------------------------------------------------------------------- 1 | type GetParcelPayload { 2 | parcelId: Int 3 | name: String 4 | company_name: String 5 | address: String 6 | address_divided: Json 7 | city: String 8 | postal_code: String 9 | telephone: String 10 | email: String 11 | date_created: String 12 | tracking_number: String 13 | weight: String 14 | label: Json 15 | status: Json 16 | data: [Json!] 17 | country: Json 18 | shipment: Json 19 | } 20 | 21 | extend type Query { 22 | getParcel(parcelId: Int!): GetParcelPayload 23 | } 24 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/get-parcel.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { parcelId } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/parcels/${parcelId}`, 19 | method: 'GET', 20 | json: true 21 | } 22 | 23 | return request(options) 24 | .then(data => { 25 | // Workaround for api-bug #224 26 | data.parcel.parcelId = data.parcel.id 27 | return { data: data.parcel } 28 | }) 29 | .catch(error => { return { error: error } }) 30 | } 31 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/get-parcels.graphql: -------------------------------------------------------------------------------- 1 | type GetParcelsPayload { 2 | parcels: [Json!]! 3 | } 4 | 5 | extend type Query { 6 | getParcels(limit: Int, offset: Int): GetParcelsPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-resource/get-parcels.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { limit, offset } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/parcels`, 19 | qs: { 20 | limit: limit || 100, 21 | offset: offset || 0 22 | }, 23 | method: 'GET', 24 | json: true 25 | } 26 | 27 | return request(options) 28 | .then(data => { return {data: data} }) 29 | .catch(error => { return error }) 30 | } 31 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-status-resource/get-parcel-statuses.graphql: -------------------------------------------------------------------------------- 1 | type GetParcelStatusesPayload { 2 | statuses: [Json!]! 3 | } 4 | 5 | extend type Query { 6 | getParcelStatuses: GetParcelStatusesPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/parcel-status-resource/get-parcel-statuses.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const options = 10 | { 11 | auth: { 12 | user: SENDCLOUD_PUBLIC_KEY, 13 | pass: SENDCLOUD_SECRET_KEY 14 | }, 15 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 16 | uri: `/parcels/statuses`, 17 | method: 'GET', 18 | json: true 19 | } 20 | 21 | return request(options) 22 | .then(data => { return { data: { statuses: data } } }) 23 | .catch(error => { return error }) 24 | } 25 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/sender-address-resource/get-sender-addresses.graphql: -------------------------------------------------------------------------------- 1 | type GetSenderAddressesPayload { 2 | sender_addresses: [Json!]! 3 | } 4 | 5 | extend type Query { 6 | getSenderAddresses: GetSenderAddressesPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/sender-address-resource/get-sender-addresses.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const options = 10 | { 11 | auth: { 12 | user: SENDCLOUD_PUBLIC_KEY, 13 | pass: SENDCLOUD_SECRET_KEY 14 | }, 15 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 16 | uri: `/user/addresses/sender`, 17 | method: 'GET', 18 | json: true 19 | } 20 | 21 | return request(options) 22 | .then(data => { return { data: data } }) 23 | .catch(error => { return error }) 24 | } 25 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/shipping-method-resource/get-shipping-method.graphql: -------------------------------------------------------------------------------- 1 | type GetShippingMethodPayload { 2 | shippingMethodId: Int 3 | name: String 4 | carrier: String 5 | price: Float 6 | min_weight: String 7 | max_weight: String 8 | countries: [Json!] 9 | service_point_input: String 10 | } 11 | 12 | extend type Query { 13 | getShippingMethod(shippingMethodId: Int!): GetShippingMethodPayload 14 | } 15 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/shipping-method-resource/get-shipping-method.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { shippingMethodId } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/shipping_methods/${shippingMethodId}`, 19 | method: 'GET', 20 | json: true 21 | } 22 | 23 | return request(options) 24 | .then(data => { 25 | // Workaround for api-bug #224 26 | data.shipping_method.shippingMethodId = data.shipping_method.id; 27 | return { data: data.shipping_method } 28 | }) 29 | .catch(error => { return error }) 30 | } 31 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/shipping-method-resource/get-shipping-methods.graphql: -------------------------------------------------------------------------------- 1 | type GetShippingMethodsPayload { 2 | shipping_methods: [Json!]! 3 | } 4 | 5 | extend type Query { 6 | getShippingMethods(senderAddressId: Int, getAll: Boolean): GetShippingMethodsPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/shipping-method-resource/get-shipping-methods.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const { senderAddressId, getAll } = event.data 10 | 11 | const options = 12 | { 13 | auth: { 14 | user: SENDCLOUD_PUBLIC_KEY, 15 | pass: SENDCLOUD_SECRET_KEY 16 | }, 17 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 18 | uri: `/shipping_methods`, 19 | method: 'GET', 20 | json: true 21 | } 22 | 23 | if (senderAddressId && getAll) return { error: "Specify either senderAddressId or getAll" } 24 | if (senderAddressId) options.qs = { sender_address: senderAddressId } 25 | else if (getAll) options.qs = { sender_address: 'all' } 26 | 27 | return request(options) 28 | .then(data => { return { data: data } }) 29 | .catch(error => { return error }) 30 | } 31 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/user-resource/get-user.graphql: -------------------------------------------------------------------------------- 1 | type GetUserPayload { 2 | user_name: String 3 | company_name: String 4 | telephone: String 5 | address: String 6 | postal_code: String 7 | city: String 8 | email: String 9 | company_logo: String 10 | registered: Date 11 | data: [Json!] 12 | modules: [Json!] 13 | invoices: [Json!] 14 | } 15 | 16 | extend type Query { 17 | getUser: GetUserPayload 18 | } 19 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/sendcloud-api/user-resource/get-user.js: -------------------------------------------------------------------------------- 1 | 'use latest' 2 | 3 | const request = require('request-promise') 4 | 5 | const SENDCLOUD_PUBLIC_KEY = '__PUBLIC_KEY__' 6 | const SENDCLOUD_SECRET_KEY = '__SECRET_KEY__' 7 | 8 | module.exports = (event) => { 9 | const options = 10 | { 11 | auth: { 12 | user: SENDCLOUD_PUBLIC_KEY, 13 | pass: SENDCLOUD_SECRET_KEY 14 | }, 15 | baseUrl: 'https://panel.sendcloud.sc/api/v2', 16 | uri: `/user`, 17 | method: 'GET', 18 | json: true 19 | } 20 | 21 | return request(options) 22 | .then(data => { return { data: data.user } }) 23 | .catch(error => { return error }) 24 | } 25 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-connect-standard-account/README.md: -------------------------------------------------------------------------------- 1 | # stripe-connect-standard-account 2 | 3 | Connect a Standard Stripe Account to your Platform with Schema Extensions and Graphcool Functions ⚡️ 4 | 5 | > Note: Schema Extensions are currently only available in the Beta Program. 6 | 7 | ## Workflow 8 | 9 | This example covers the following scenario: An already registered users wants to connect his standard account to your platform. 10 | 11 | This is the workflow: 12 | * First, we check if the user id provided as function argument matches the user id embedded in the authentication token of the `Authorization` header. 13 | * We pass the provided Stripe authentication code (previously obtained in the frontend) to fetch the user details from the Stripe API 14 | * We update the `User` node stored in the Graphcool project with the relevant user credentials obtained from Stripe 15 | 16 | For more information refer to the [official Stripe documentation](https://stripe.com/docs/connect/standard-accounts). 17 | 18 | ## Contributions 19 | 20 | Thanks so much [@picosam](https://github.com/picosam) for contributing this example :tada: 21 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-connect-standard-account/schema-extension.graphql: -------------------------------------------------------------------------------- 1 | type FetchStripeAccountIdPayload { 2 | id: ID! 3 | } 4 | 5 | extend type Mutation { 6 | fetchStripeAccountId(userId: ID!, authCode: String!): FetchStripeAccountIdPayload 7 | } 8 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-connect-standard-account/stripe-account.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: ID! 3 | 4 | # Representative of a Stripe Account ID 5 | stripeId: String @isUnique 6 | } 7 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-coupons/README.md: -------------------------------------------------------------------------------- 1 | # stripe-coupons 2 | 3 | Check if a Stripe Coupon exists with Graphcool Functions ⚡️ 4 | 5 | ## Getting Started 6 | 7 | ```sh 8 | npm -g install graphcool 9 | graphcool init --schema stripe-coupons.graphql 10 | ``` 11 | 12 | ## Setup Stripe 13 | 14 | * Create a new Coupon at Stripe with a fixed price reduction and use the key `my-coupon-code`. 15 | 16 | * Replace `__STRIPE_KEY__` in `stripe-coupons.js` with your **test Stripe key**. 17 | 18 | * Create a new function as part of the **`PRE_WRITE` step of the Request Pipeline** and paste the code from `stripe-coupons.js`. This will check if the coupon code exists whenever an Coupon is created. 19 | 20 | ## Test the Code 21 | 22 | Go to the Graphcool Playground: 23 | 24 | ```sh 25 | graphcool playground 26 | ``` 27 | 28 | Run this mutation to create a new coupon and trigger the coupon check: 29 | 30 | ```graphql 31 | mutation testStripeCoupon { 32 | createCoupon( 33 | key: "my-coupon-code" 34 | ) { 35 | id 36 | } 37 | } 38 | ``` 39 | 40 | This should return the `id` of the new coupon node, because `my-coupon-code` is a valid code. 41 | 42 | Run this mutation to create a new coupon and trigger the coupon check: 43 | 44 | ```graphql 45 | mutation testStripeCoupon { 46 | createCoupon( 47 | key: "wrong-code" 48 | ) { 49 | id 50 | } 51 | } 52 | ``` 53 | 54 | This should return an error message, because `wrong-code` is an invalid code. 55 | 56 | ![](http://i.imgur.com/5RHR6Ku.png) 57 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-coupons/check-coupon.js: -------------------------------------------------------------------------------- 1 | const stripe = require('stripe')('__STRIPE_KEY__') 2 | 3 | module.exports = function (event) { 4 | const code = event.data.key 5 | return new Promise(function(resolve, reject) { 6 | return stripe.coupons.retrieve( 7 | code, 8 | function(err, response) { 9 | if (err) { 10 | console.log(`Invalid coupon code '${code}' requested`) 11 | resolve({error: 'Coupon code is invalid'}) 12 | } else { 13 | console.log(`Valid coupon code '${code}' requested`) 14 | resolve(event) 15 | } 16 | } 17 | ) 18 | }) 19 | } 20 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-coupons/stripe-coupons.graphql: -------------------------------------------------------------------------------- 1 | type Coupon { 2 | id: ID! 3 | key: String! 4 | } 5 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-charge/User.graphql: -------------------------------------------------------------------------------- 1 | type User implements Node { 2 | createdAt: DateTime! 3 | id: ID! @isUnique 4 | email: String! 5 | firstName: String! 6 | lastName: String! 7 | isPaid: Boolean! @defaultValue(value: false) 8 | stripeCustomerId: String 9 | stripeToken: String 10 | updatedAt: DateTime! 11 | } 12 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-charge/subscription.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | User(filter: { 3 | mutation_in: [UPDATED] 4 | updatedFields_contains: "stripeToken" 5 | node: { 6 | stripeToken_not: "null" 7 | } 8 | }) { 9 | updatedFields 10 | node { 11 | id 12 | email 13 | firstName 14 | lastName 15 | stripeToken 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "es2015", 5 | { 6 | "modules": false 7 | } 8 | ], 9 | "latest", 10 | "stage-0" 11 | ], 12 | "plugins": [ 13 | "array-includes", 14 | "transform-async-to-generator", 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | jest_* 4 | node_modules 5 | npm-debug.log 6 | dist 7 | test/coverage 8 | .eslintcache 9 | yarn-error.log 10 | jest 11 | /buildTools/graphql/schema.graphql 12 | /buildTools/graphql/updateSchema.js.transpiled 13 | /buildTools/graphql/schema.json 14 | /src/universal/data/raw.json 15 | .**sw* 16 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stripe-create-customer", 3 | "version": "1.0.0", 4 | "description": "Example Graphcool Server Side Subscription function to create stripe customers", 5 | "main": "src/createStripeCustomer.js", 6 | "scripts": { 7 | "test": "jest --watchAll", 8 | "build": "webpack" 9 | }, 10 | "author": "Yusinto Ngadiman", 11 | "homepage": "reactjunkie.com", 12 | "license": "ISC", 13 | "dependencies": { 14 | "isomorphic-fetch": "^2.2.1", 15 | "stripe": "^4.22.0" 16 | }, 17 | "devDependencies": { 18 | "babel-core": "^6.24.1", 19 | "babel-loader": "^7.0.0", 20 | "babel-plugin-array-includes": "^2.0.3", 21 | "babel-plugin-transform-async-to-generator": "^6.24.1", 22 | "babel-polyfill": "^6.23.0", 23 | "babel-preset-es2015": "^6.24.1", 24 | "babel-preset-latest": "^6.24.1", 25 | "babel-preset-stage-0": "^6.24.1", 26 | "jest": "^20.0.4", 27 | "webpack": "^2.6.1", 28 | "webpack-node-externals": "^1.6.0" 29 | }, 30 | "jest": { 31 | "setupFiles": [ 32 | "./test/testSetup.js" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/src/constants.js: -------------------------------------------------------------------------------- 1 | export const stripeKey = '__STRIPE_KEY__'; 2 | export const graphCoolEndpoint = 'https://api.graph.cool/simple/v1/__PROJECT_ID__'; -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/src/customer.graphql: -------------------------------------------------------------------------------- 1 | type Customer implements Node { 2 | createdAt: DateTime! 3 | email: String! 4 | id: ID! @isUnique 5 | stripeCustomerId: String 6 | updatedAt: DateTime! 7 | } -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/src/subscription.graphql: -------------------------------------------------------------------------------- 1 | # Use this subscription query when setting up your server side subscription 2 | subscription { 3 | Customer(filter: { 4 | mutation_in: [CREATED] 5 | }) { 6 | updatedFields 7 | node { 8 | id 9 | stripeCustomerId 10 | email 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/test/fetchMock.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Global mock for isomorphic-fetch 3 | */ 4 | 5 | const fetch = jest.fn(); 6 | 7 | const response = (status, statusText, ok, body) => { 8 | return { 9 | url: '', 10 | status, 11 | statusText, 12 | ok, 13 | json: () => body, 14 | } 15 | }; 16 | 17 | fetch.mockSuccess = (body, opts = {ok: true, status: 200, statusText: ''}) => 18 | fetch.mockImplementationOnce(() => 19 | Promise.resolve(response(opts.status, opts.statusText, opts.ok, body))); 20 | 21 | fetch.mockFailure = (error) => fetch.mockImplementationOnce(() => Promise.reject(error)); 22 | 23 | export default fetch; 24 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/test/testSetup.js: -------------------------------------------------------------------------------- 1 | import fetchMock from './fetchMock'; 2 | 3 | global.fetch = fetchMock; 4 | -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer-es6/webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const path = require('path'); 3 | const nodeExternals = require('webpack-node-externals'); 4 | const functionToBuild = 'createStripeCustomer'; 5 | 6 | module.exports = { 7 | entry: ['babel-polyfill', `./src/${functionToBuild}`], 8 | output: { 9 | path: path.join(__dirname, 'dist'), 10 | library: '[name]', 11 | libraryTarget: 'commonjs2', 12 | filename: `${functionToBuild}.js` 13 | }, 14 | externals: [nodeExternals({ 15 | whitelist: ['babel-polyfill', 'regenerator-runtime/runtime']} 16 | )], 17 | target: 'node', 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.js$/, 22 | exclude: /node_modules/, 23 | loader: 'babel-loader', 24 | options: { 25 | presets: ['es2015'], 26 | } 27 | } 28 | ] 29 | }, 30 | plugins: [ 31 | new webpack.optimize.UglifyJsPlugin({ 32 | compress: { 33 | warnings: false, 34 | screw_ie8: true, 35 | conditionals: true, 36 | unused: true, 37 | comparisons: true, 38 | sequences: true, 39 | dead_code: true, 40 | evaluate: true, 41 | join_vars: true, 42 | if_return: true 43 | }, 44 | }), 45 | ] 46 | }; -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer/customer.graphql: -------------------------------------------------------------------------------- 1 | type Customer implements Node { 2 | createdAt: DateTime! 3 | email: String! 4 | id: ID! @isUnique 5 | stripeCustomerId: String 6 | updatedAt: DateTime! 7 | } -------------------------------------------------------------------------------- /outdated/payment-and-delivery/stripe-create-customer/subscription.graphql: -------------------------------------------------------------------------------- 1 | # Use this subscription query when setting up your server side subscription 2 | subscription { 3 | Customer(filter: { 4 | mutation_in: [CREATED] 5 | }) { 6 | updatedFields 7 | node { 8 | id 9 | stripeCustomerId 10 | email 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /outdated/sendgrid/docs/step-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/sendgrid/docs/step-01.png -------------------------------------------------------------------------------- /outdated/sendgrid/docs/step-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/sendgrid/docs/step-02.png -------------------------------------------------------------------------------- /outdated/sendgrid/docs/step-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/sendgrid/docs/step-03.png -------------------------------------------------------------------------------- /outdated/sendgrid/docs/step-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/sendgrid/docs/step-04.png -------------------------------------------------------------------------------- /outdated/sendgrid/graphcool.yml: -------------------------------------------------------------------------------- 1 | # GraphQL types 2 | types: ./types.graphql 3 | 4 | # functions 5 | functions: 6 | sendEmail: 7 | handler: 8 | code: 9 | src: ./src/sendEmail.ts 10 | environment: 11 | SENDGRID_API_KEY: ${env:SENDGRID_API_KEY} 12 | type: resolver 13 | schema: ./src/sendEmail.graphql 14 | -------------------------------------------------------------------------------- /outdated/sendgrid/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphcool-lib": "^0.1.0", 4 | "isomorphic-fetch": "^2.2.1", 5 | "sendgrid": "^5.2.3" 6 | }, 7 | "devDependencies": { 8 | "@types/node": "^8.0.45" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /outdated/sendgrid/src/sendEmail.graphql: -------------------------------------------------------------------------------- 1 | type SendEmailPayload { 2 | success: Boolean! 3 | } 4 | 5 | extend type Mutation { 6 | sendEmail( 7 | from: String! 8 | to: String! 9 | subject: String! 10 | content: String! 11 | ): SendEmailPayload 12 | } 13 | -------------------------------------------------------------------------------- /outdated/sendgrid/types.graphql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma-archive/graphcool-templates/e9ad3b8d9c9105e24aab48c661cbc38201e1190e/outdated/sendgrid/types.graphql -------------------------------------------------------------------------------- /outdated/syncing/algolia/graphcool.yml: -------------------------------------------------------------------------------- 1 | types: ./types.graphql 2 | 3 | functions: 4 | syncModel: 5 | handler: 6 | code: 7 | src: ./src/sync.js 8 | environment: 9 | ALGOLIA_APP_ID: ${env:ALGOLIA_APP_ID} 10 | ALGOLIA_API_KEY: ${env:ALGOLIA_API_KEY} 11 | ALGOLIA_INDEX_NAME: ${env:ALGOLIA_INDEX_NAME} 12 | type: subscription 13 | query: ./src/syncQuery.graphql 14 | 15 | permissions: 16 | - operation: SyncModel.read 17 | - operation: SyncModel.create 18 | - operation: SyncModel.update 19 | - operation: SyncModel.delete 20 | -------------------------------------------------------------------------------- /outdated/syncing/algolia/src/sync.js: -------------------------------------------------------------------------------- 1 | const algoliasearch = require('algoliasearch') 2 | 3 | const client = algoliasearch('ALGOLIA_APP_ID', 'ALGOLIA_API_KEY') 4 | const index = client.initIndex('ALGOLIA_INDEX_NAME') 5 | 6 | const modelName = 'SyncModel' 7 | 8 | module.exports = event => { 9 | 10 | if (!process.env['ALGOLIA_APP_ID']) { 11 | console.log('Please provide a valid Algolia app id!') 12 | return { error: 'Module not configured correctly.' } 13 | } 14 | 15 | if (!process.env['ALGOLIA_API_KEY']) { 16 | console.log('Please provide a valid Algolia api key!') 17 | return { error: 'Module not configured correctly.' } 18 | } 19 | 20 | if (!process.env['ALGOLIA_INDEX_NAME']) { 21 | console.log('Please provide a valid Algolia index name!') 22 | return { error: 'Module not configured correctly.' } 23 | } 24 | 25 | const mutation = event.data[modelName].mutation 26 | const node = event.data[modelName].node 27 | const previousValues = event.data[modelName].previousValues 28 | 29 | switch (mutation) { 30 | case 'CREATED': 31 | return syncAddedNode(node) 32 | case 'UPDATED': 33 | return syncUpdatedNode(node) 34 | case 'DELETED': 35 | return syncDeletedNode(previousValues) 36 | default: 37 | console.log(`mutation was '${mutation}'. Unable to sync node.`) 38 | return Promise.resolve() 39 | } 40 | } 41 | 42 | function syncAddedNode(node) { 43 | console.log('Adding node') 44 | return index.addObject(node) 45 | } 46 | 47 | function syncUpdatedNode(node) { 48 | console.log('Updating node') 49 | return index.saveObject(node) 50 | } 51 | 52 | function syncDeletedNode(node) { 53 | console.log('Deleting node') 54 | return index.deleteObject(node.objectID) 55 | } 56 | -------------------------------------------------------------------------------- /outdated/syncing/algolia/src/syncQuery.graphql: -------------------------------------------------------------------------------- 1 | subscription { 2 | SyncModel(filter: { 3 | mutation_in: [CREATED, UPDATED, DELETED] 4 | }) { 5 | mutation 6 | previousValues { 7 | objectID: id 8 | } 9 | node { 10 | objectID: id 11 | name 12 | points 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /outdated/syncing/algolia/types.graphql: -------------------------------------------------------------------------------- 1 | type SyncModel { 2 | # required system field: 3 | id: ID! @isUnique 4 | 5 | # optional system fields. uncomment if you need them: 6 | # createdAt: DateTime! 7 | # updatedAt: DateTime! 8 | 9 | name: String! 10 | points: Int 11 | } 12 | -------------------------------------------------------------------------------- /templates.json: -------------------------------------------------------------------------------- 1 | { 2 | "auth0": { 3 | "path": "auth/auth0", 4 | "description": "Authentication using Auth0" 5 | }, 6 | "email-password": { 7 | "path": "auth/email-password", 8 | "description": "Simple email-password based authentication" 9 | }, 10 | "facebook-auth": { 11 | "path": "auth/facebook", 12 | "description": "Authentication using Facebook OAuth2" 13 | }, 14 | "github-auth": { 15 | "path": "auth/github", 16 | "description": "Authentication using Github OAuth2" 17 | }, 18 | "google-auth": { 19 | "path": "auth/google", 20 | "description": "Authentication using Google OAuth2" 21 | }, 22 | "fixer": { 23 | "path": "misc/fixer", 24 | "description": "GraphQL wrapper for fixer.io" 25 | }, 26 | "mailgun": { 27 | "path": "messaging/mailgun", 28 | "description": "Send emails with Mailgun" 29 | }, 30 | "pusher": { 31 | "path": "messaging/pusher", 32 | "description": "Send Push Notifications with Pusher" 33 | }, 34 | "ses": { 35 | "path": "messaging/ses", 36 | "description": "Send emails with AWS SES" 37 | }, 38 | "twilio": { 39 | "path": "messaging/twilio", 40 | "description": "Send SMS with Twilio" 41 | } 42 | } 43 | --------------------------------------------------------------------------------