├── .babelrc ├── .dockerignore ├── .gitignore ├── README.md ├── app └── public │ ├── index.html │ └── js │ ├── bundle.min.js │ └── index.js ├── config └── config.json ├── graphql-playground.png ├── models ├── author.js ├── index.js └── post.js ├── package-lock.json ├── package.json ├── resolvers.js ├── schema.js └── server.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env", 4 | "stage-3" 5 | ] 6 | } -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # do not copy into docker images 2 | 3 | node_modules 4 | npm-debug.log -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Setup a GraphQL API with Apollo 2.0 Sequelize and Express.js 2 | 3 | ## Instructions 4 | Please do follow the instructions in the article published on [medium](https://medium.com/infocentric/setup-a-graphql-api-with-apollo-2-0-sequelize-and-express-js-608d1365d776). 5 | -------------------------------------------------------------------------------- /app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Post overview 9 | 23 | 24 | 25 | 26 |

Posts and their author

27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/public/js/bundle.min.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=26)}([function(e,t,r){"use strict";r.r(t);var n=r(20),i=r.n(n).a,o=r(6),a=r(2),u=function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r2&&void 0!==arguments[2]?arguments[2]:n,u=void 0,c=Array.isArray(e),s=[e],l=-1,f=[],d=void 0,p=void 0,h=void 0,v=[],y=[],m=e;do{var b=++l===s.length,g=b&&0!==f.length;if(b){if(p=0===y.length?void 0:v[v.length-1],d=h,h=y.pop(),g){if(c)d=d.slice();else{var O={};for(var w in d)d.hasOwnProperty(w)&&(O[w]=d[w]);d=O}for(var E=0,k=0;k-1}function u(e){return["IntValue","FloatValue"].indexOf(e.kind)>-1}function c(e,t,r,n){if(function(e){return"IntValue"===e.kind}(r)||function(e){return"FloatValue"===e.kind}(r))e[t.value]=Number(r.value);else if(function(e){return"BooleanValue"===e.kind}(r)||function(e){return"StringValue"===e.kind}(r))e[t.value]=r.value;else if(function(e){return"ObjectValue"===e.kind}(r)){var i={};r.fields.map(function(e){return c(i,e.name,e.value,n)}),e[t.value]=i}else if(function(e){return"Variable"===e.kind}(r)){var o=(n||{})[r.name.value];e[t.value]=o}else if(function(e){return"ListValue"===e.kind}(r))e[t.value]=r.values.map(function(e){var r={};return c(r,t,e,n),r[t.value]});else if(function(e){return"EnumValue"===e.kind}(r))e[t.value]=r.value;else{if(!function(e){return"NullValue"===e.kind}(r))throw new Error('The inline argument "'+t.value+'" of kind "'+r.kind+'"is not supported. Use variables instead of inline arguments to overcome this limitation.');e[t.value]=null}}function s(e,t){var r=null;e.directives&&(r={},e.directives.forEach(function(e){r[e.name.value]={},e.arguments&&e.arguments.forEach(function(n){var i=n.name,o=n.value;return c(r[e.name.value],i,o,t)})}));var n=null;return e.arguments&&e.arguments.length&&(n={},e.arguments.forEach(function(e){var r=e.name,i=e.value;return c(n,r,i,t)})),f(e.name.value,n,r)}var l=["connection","include","skip","client","rest","export"];function f(e,t,r){if(r&&r.connection&&r.connection.key){if(r.connection.filter&&r.connection.filter.length>0){var n=r.connection.filter?r.connection.filter:[];n.sort();var o=t,a={};return n.forEach(function(e){a[e]=o[e]}),r.connection.key+"("+JSON.stringify(a)+")"}return r.connection.key}var u=e;if(t){var c=i()(t);u+="("+c+")"}return r&&Object.keys(r).forEach(function(e){-1===l.indexOf(e)&&(r[e]&&Object.keys(r[e]).length?u+="@"+e+"("+JSON.stringify(r[e])+")":u+="@"+e)}),u}function d(e,t){if(e.arguments&&e.arguments.length){var r={};return e.arguments.forEach(function(e){var n=e.name,i=e.value;return c(r,n,i,t)}),r}return null}function p(e){return e.alias?e.alias.value:e.name.value}function h(e){return"Field"===e.kind}function v(e){return"InlineFragment"===e.kind}function y(e){return e&&"id"===e.type}function m(e,t){return void 0===t&&(t=!1),o({type:"id",generated:t},"string"==typeof e?{id:e,typename:void 0}:e)}function b(e){return null!=e&&"object"==typeof e&&"json"===e.type}function g(e){throw new Error("Variable nodes are not supported by valueFromNode")}function O(e,t){switch(void 0===t&&(t=g),e.kind){case"Variable":return t(e);case"NullValue":return null;case"IntValue":return parseInt(e.value,10);case"FloatValue":return parseFloat(e.value);case"ListValue":return e.values.map(function(e){return O(e,t)});case"ObjectValue":for(var r={},n=0,i=e.fields;n1)throw new Error("Ambiguous GraphQL document: contains "+t.length+" operations")}function u(e){return a(e),e.definitions.filter(function(e){return"OperationDefinition"===e.kind})[0]}function c(e){var t=u(e);if(!t)throw new Error("GraphQL document is missing an operation");return t}function s(e){return e.definitions.filter(function(e){return"OperationDefinition"===e.kind&&e.name}).map(function(e){return e.name.value})[0]||null}function l(e){return e.definitions.filter(function(e){return"FragmentDefinition"===e.kind})}function f(e){var t=u(e);if(!t||"query"!==t.operation)throw new Error("Must contain a query definition.");return t}function d(e){if("Document"!==e.kind)throw new Error('Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql');if(e.definitions.length>1)throw new Error("Fragment must have exactly one definition.");var t=e.definitions[0];if("FragmentDefinition"!==t.kind)throw new Error("Must be a fragment definition.");return t}function p(e){var t;a(e);for(var r=0,n=e.definitions;r0}function u(e){return function(t){return e.some(function(e){return!(!e.name||e.name!==t.name.value)||!(!e.test||!e.test(t))})}}function c(e,t){var r=Object(n.a)(t);return r.definitions.forEach(function(t){!function e(t,r){if(!r.selections)return r;var n=t.some(function(e){return e.remove});return r.selections=r.selections.map(function(e){if("Field"!==e.kind||!e||!e.directives)return e;var r,i=u(t);return e.directives=e.directives.filter(function(e){var t=!i(e);return r||t||!n||(r=!0),t}),r?null:e}).filter(function(e){return!!e}),r.selections.forEach(function(r){"Field"!==r.kind&&"InlineFragment"!==r.kind||!r.selectionSet||e(t,r.selectionSet)}),r}(e,t.selectionSet)}),a(Object(i.i)(r),Object(i.b)(Object(i.e)(r)))?r:null}function s(e){Object(i.a)(e);var t=Object(n.a)(e);return t.definitions.forEach(function(e){var t="OperationDefinition"===e.kind;!function e(t,r){void 0===r&&(r=!1),t.selections&&(r||t.selections.some(function(e){return"Field"===e.kind&&"__typename"===e.name.value})||t.selections.push(o),t.selections.forEach(function(t){"Field"===t.kind?0!==t.name.value.lastIndexOf("__",0)&&t.selectionSet&&e(t.selectionSet):"InlineFragment"===t.kind&&t.selectionSet&&e(t.selectionSet)}))}(e.selectionSet,t)}),t}var l={test:function(e){var t="connection"===e.name.value;return t&&(e.arguments&&e.arguments.some(function(e){return"key"===e.name.value})||console.warn("Removing an @connection directive even though it does not have a key. You may want to use the key parameter to specify a store key.")),t}};function f(e){return Object(i.a)(e),c([l],e)}function d(e,t,r){if(void 0===r&&(r=!0),"Field"!==t.kind||!t)return!0;if(!t.directives)return!1;var n=u(e);return t.directives.filter(n).length>0||r&&function(e,t,r){return void 0===r&&(r=!0),!(!t||!t.selections)&&t.selections.filter(function(t){return d(e,t,r)}).length>0}(e,t.selectionSet,r)}function p(e,t,r){void 0===r&&(r=!1),Object(i.a)(t);var o=Object(n.a)(t);return o.definitions=o.definitions.map(function(t){return("OperationDefinition"===t.kind||"FragmentDefinition"===t.kind&&!r)&&t.selectionSet&&(t.selectionSet=function e(t,r){return r.selections=r.selections.filter(function(e){return d(t,e,!0)}).map(function(r){return d(t,r,!1)?r:("Field"!==r.kind&&"InlineFragment"!==r.kind||!r.selectionSet||(r.selectionSet=e(t,r.selectionSet)),r)}),r}(e,t.selectionSet)),t}),a(Object(i.i)(o),Object(i.b)(Object(i.e)(o)))?o:null}},function(e,t,r){"use strict";r.d(t,"b",function(){return i}),r.d(t,"e",function(){return o}),r.d(t,"a",function(){return a}),r.d(t,"c",function(){return u}),r.d(t,"d",function(){return c});var n=r(4);function i(e,t){if(e.directives&&e.directives.length){var r={};return e.directives.forEach(function(e){r[e.name.value]=Object(n.a)(e,t)}),r}return null}function o(e,t){if(void 0===t&&(t={}),!e.directives)return!0;var r=!0;return e.directives.forEach(function(e){if("skip"===e.name.value||"include"===e.name.value){var n=e.arguments||[],i=e.name.value;if(1!==n.length)throw new Error("Incorrect number of arguments for the @"+i+" directive.");var o=n[0];if(!o.name||"if"!==o.name.value)throw new Error("Invalid argument for the @"+i+" directive.");var a=n[0].value,u=!1;if(a&&"BooleanValue"===a.kind)u=a.value;else{if("Variable"!==a.kind)throw new Error("Argument for the @"+i+" directive must be a variable or a boolean value.");if(void 0===(u=t[a.name.value]))throw new Error("Invalid variable referenced in @"+i+" directive.")}"skip"===i&&(u=!u),u||(r=!1)}}),r}function a(e){return e.selectionSet&&e.selectionSet.selections.length>0?[e].concat(e.selectionSet.selections.map(function(e){return[e].concat(a(e))}).reduce(function(e,t){return e.concat(t)},[])):[e]}function u(e){return e.definitions.filter(function(e){return e.selectionSet&&e.selectionSet.selections}).map(function(e){return a(e)}).reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return e.directives&&e.directives.length>0}).map(function(e){return e.directives}).reduce(function(e,t){return e.concat(t)},[]).map(function(e){return e.name.value})}function c(e,t){return u(t).some(function(t){return e.indexOf(t)>-1})}},function(e,t,r){"use strict";r.d(t,"a",function(){return o});var n=r(3),i=Object.create({});function o(e,t){if(void 0===t&&(t="warn"),!Object(n.d)()&&!i[e])switch(Object(n.e)()||(i[e]=!0),t){case"error":console.error(e);break;default:console.warn(e)}}},function(e,t,r){"use strict";r.d(t,"a",function(){return i});var n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&"none"===t||e.networkError)}(e,this.options.errorPolicy))return{data:{},loading:!1,networkStatus:e.networkStatus,error:new y({graphQLErrors:e.graphQLErrors,networkError:e.networkError})};var t,r=this.queryManager.getCurrentQueryResult(this),i=r.data,o=r.partial,a=!e||e.networkStatus===n.loading,u="network-only"===this.options.fetchPolicy&&a||o&&"cache-only"!==this.options.fetchPolicy,s={data:i,loading:c(t=e?e.networkStatus:u?n.loading:n.ready),networkStatus:t};if(e&&e.graphQLErrors&&"all"===this.options.errorPolicy&&(s.errors=e.graphQLErrors),!o){this.lastResult=b({},s,{stale:!1})}return b({},s,{partial:o})},t.prototype.getLastResult=function(){return this.lastResult},t.prototype.getLastError=function(){return this.lastError},t.prototype.resetLastResults=function(){delete this.lastResult,delete this.lastError,this.isTornDown=!1},t.prototype.refetch=function(e){var t=this.options.fetchPolicy;if("cache-only"===t)return Promise.reject(new Error("cache-only fetchPolicy option should not be used together with query refetch."));Object(o.a)(this.variables,e)||(this.variables=Object.assign({},this.variables,e)),Object(o.a)(this.options.variables,this.variables)||(this.options.variables=Object.assign({},this.options.variables,this.variables));var r="network-only"===t||"no-cache"===t,n=b({},this.options,{fetchPolicy:r?t:"network-only"});return this.queryManager.fetchQuery(this.queryId,n,h.refetch).then(function(e){return Object(a.a)(e)})},t.prototype.fetchMore=function(e){var t,r=this;if(!e.updateQuery)throw new Error("updateQuery option is required. This function defines how to update the query data with the new results.");return Promise.resolve().then(function(){var n=r.queryManager.generateQueryId();return(t=e.query?e:b({},r.options,e,{variables:Object.assign({},r.variables,e.variables)})).fetchPolicy="network-only",r.queryManager.fetchQuery(n,t,h.normal,r.queryId)}).then(function(n){return r.updateQuery(function(r){return e.updateQuery(r,{fetchMoreResult:n.data,variables:t.variables})}),n})},t.prototype.subscribeToMore=function(e){var t=this,r=this.queryManager.startGraphQLSubscription({query:e.document,variables:e.variables}).subscribe({next:function(r){e.updateQuery&&t.updateQuery(function(t,n){var i=n.variables;return e.updateQuery(t,{subscriptionData:r,variables:i})})},error:function(t){e.onError?e.onError(t):console.error("Unhandled GraphQL subscription error",t)}});return this.subscriptionHandles.push(r),function(){var e=t.subscriptionHandles.indexOf(r);e>=0&&(t.subscriptionHandles.splice(e,1),r.unsubscribe())}},t.prototype.setOptions=function(e){var t=this.options;this.options=Object.assign({},this.options,e),e.pollInterval?this.startPolling(e.pollInterval):0===e.pollInterval&&this.stopPolling();var r="network-only"!==t.fetchPolicy&&"network-only"===e.fetchPolicy||"cache-only"===t.fetchPolicy&&"cache-only"!==e.fetchPolicy||"standby"===t.fetchPolicy&&"standby"!==e.fetchPolicy||!1;return this.setVariables(this.options.variables,r,e.fetchResults)},t.prototype.setVariables=function(e,t,r){void 0===t&&(t=!1),void 0===r&&(r=!0),this.isTornDown=!1;var n=e||this.variables;return Object(o.a)(n,this.variables)&&!t?0!==this.observers.length&&r?this.result():new Promise(function(e){return e()}):(this.variables=n,this.options.variables=n,0===this.observers.length?new Promise(function(e){return e()}):this.queryManager.fetchQuery(this.queryId,b({},this.options,{variables:this.variables})).then(function(e){return Object(a.a)(e)}))},t.prototype.updateQuery=function(e){var t=this.queryManager.getQueryWithPreviousResult(this.queryId),r=t.previousResult,n=t.variables,i=t.document,o=Object(u.b)(function(){return e(r,{variables:n})});o&&(this.queryManager.dataStore.markUpdateQueryResult(i,n,o),this.queryManager.broadcastQueries())},t.prototype.stopPolling=function(){this.isCurrentlyPolling&&(this.scheduler.stopPollingQuery(this.queryId),this.options.pollInterval=void 0,this.isCurrentlyPolling=!1)},t.prototype.startPolling=function(e){if("cache-first"===this.options.fetchPolicy||"cache-only"===this.options.fetchPolicy)throw new Error("Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.");this.isCurrentlyPolling&&(this.scheduler.stopPollingQuery(this.queryId),this.isCurrentlyPolling=!1),this.options.pollInterval=e,this.isCurrentlyPolling=!0,this.scheduler.startPollingQuery(this.options,this.queryId)},t.prototype.onSubscribe=function(e){var t=this;return e._subscription&&e._subscription._observer&&!e._subscription._observer.error&&(e._subscription._observer.error=function(e){console.error("Unhandled error",e.message,e.stack)}),this.observers.push(e),e.next&&this.lastResult&&e.next(this.lastResult),e.error&&this.lastError&&e.error(this.lastError),1===this.observers.length&&this.setUpQuery(),function(){t.observers=t.observers.filter(function(t){return t!==e}),0===t.observers.length&&t.tearDownQuery()}},t.prototype.setUpQuery=function(){var e=this;if(this.shouldSubscribe&&this.queryManager.addObservableQuery(this.queryId,this),this.options.pollInterval){if("cache-first"===this.options.fetchPolicy||"cache-only"===this.options.fetchPolicy)throw new Error("Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.");this.isCurrentlyPolling=!0,this.scheduler.startPollingQuery(this.options,this.queryId)}var t={next:function(t){e.lastResult=t,e.observers.forEach(function(e){return e.next&&e.next(t)})},error:function(t){e.lastError=t,e.observers.forEach(function(e){return e.error&&e.error(t)})}};this.queryManager.startQuery(this.queryId,this.options,this.queryManager.queryListenerForObserver(this.queryId,this.options,t))},t.prototype.tearDownQuery=function(){this.isTornDown=!0,this.isCurrentlyPolling&&(this.scheduler.stopPollingQuery(this.queryId),this.isCurrentlyPolling=!1),this.subscriptionHandles.forEach(function(e){return e.unsubscribe()}),this.subscriptionHandles=[],this.queryManager.removeObservableQuery(this.queryId),this.queryManager.stopQuery(this.queryId),this.observers=[]},t}(d),O=r(13),w=r(3),E=function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),k=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.inFlightRequestObservables=new Map,t.subscribers=new Map,t}return E(t,e),t.prototype.request=function(e,t){var r=this;if(e.getContext().forceFetch)return t(e);var n=e.toKey(),i=function(e){return r.inFlightRequestObservables.delete(e),r.subscribers.get(e)};if(!this.inFlightRequestObservables.get(n)){var o,a=t(e),u=new s.Observable(function(e){var t=r.subscribers.get(n);return t||(t={next:[],error:[],complete:[]}),r.subscribers.set(n,{next:t.next.concat([e.next.bind(e)]),error:t.error.concat([e.error.bind(e)]),complete:t.complete.concat([e.complete.bind(e)])}),o||(o=a.subscribe({next:function(e){var t=i(n);r.subscribers.delete(n),t&&(t.next.forEach(function(t){return t(e)}),t.complete.forEach(function(e){return e()}))},error:function(e){var t=i(n);r.subscribers.delete(n),t&&t.error.forEach(function(t){return t(e)})}})),function(){o&&o.unsubscribe(),r.inFlightRequestObservables.delete(n)}});this.inFlightRequestObservables.set(n,u)}return this.inFlightRequestObservables.get(n)},t}(s.ApolloLink),I=r(7),_=r(6),T=r(14),N=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0?this.intervalQueries[n].push(e):(this.intervalQueries[n]=[e],this.pollingTimers[n]=setInterval(function(){r.fetchQueriesOnInterval(n)},n))},e.prototype.registerPollingQuery=function(e){if(!e.pollInterval)throw new Error("Attempted to register a non-polling query with the scheduler.");return new g({scheduler:this,options:e})},e}(),j=function(){function e(){this.store={}}return e.prototype.getStore=function(){return this.store},e.prototype.get=function(e){return this.store[e]},e.prototype.initMutation=function(e,t,r){this.store[e]={mutationString:t,variables:r||{},loading:!0,error:null}},e.prototype.markMutationError=function(e,t){var r=this.store[e];r&&(r.loading=!1,r.error=t)},e.prototype.markMutationResult=function(e){var t=this.store[e];t&&(t.loading=!1,t.error=null)},e.prototype.reset=function(){this.store={}},e}(),P=Object.assign||function(e){for(var t,r=1,n=arguments.length;r-1}).reduce(function(e,r){return e[r]=P({},t.store[r],{networkStatus:n.loading}),e},{})},e}(),Q=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]=(r||1)&&(o.queryStore.markQueryError(e,t,n),o.invalidate(!0,e,n),o.broadcastQueries()),o.removeFetchQueryPromise(O),new y({networkError:t})});if("cache-and-network"!==f)return E;E.catch(function(){})}return Promise.resolve({data:i})},e.prototype.queryListenerForObserver=function(e,t,r){var n=this,o=!1;return function(u,s){if(n.invalidate(!1,e),u){var l=n.getQuery(e).observableQuery,f=l?l.options.fetchPolicy:t.fetchPolicy;if("standby"!==f){var d=l?l.options.errorPolicy:t.errorPolicy,p=l?l.getLastResult():null,h=l?l.getLastError():null,v=!s&&null!=u.previousVariables||"cache-only"===f||"cache-and-network"===f,m=Boolean(p&&u.networkStatus!==p.networkStatus),b=d&&(h&&h.graphQLErrors)!==u.graphQLErrors&&"none"!==d;if(!c(u.networkStatus)||m&&t.notifyOnNetworkStatusChange||v){if((!d||"none"===d)&&u.graphQLErrors&&u.graphQLErrors.length>0||u.networkError){var g=new y({graphQLErrors:u.graphQLErrors,networkError:u.networkError});if(o=!0,r.error)try{r.error(g)}catch(e){setTimeout(function(){throw e},0)}else setTimeout(function(){throw g},0),Object(w.d)()||console.info("An unhandled error was thrown because no error handler is registered for the query "+Object(i.a)(u.document));return}try{var O=void 0,E=void 0;if(s)"no-cache"!==f&&n.setQuery(e,function(){return{newData:null}}),O=s.result,E=!s.complete||!1;else if(p&&p.data&&!b)O=p.data,E=!1;else{var k=n.getQuery(e).document,I=n.dataStore.getCache().diff({query:k,variables:u.previousVariables||u.variables,optimistic:!0});O=I.result,E=!I.complete}var _=void 0;if(_=E&&"cache-only"!==f?{data:p&&p.data,loading:c(u.networkStatus),networkStatus:u.networkStatus,stale:!0}:{data:O,loading:c(u.networkStatus),networkStatus:u.networkStatus,stale:!1},"all"===d&&u.graphQLErrors&&u.graphQLErrors.length>0&&(_.errors=u.graphQLErrors),r.next)if(!(p&&_&&p.networkStatus===_.networkStatus&&p.stale===_.stale&&p.data===_.data)||o)try{r.next(Object(a.a)(_))}catch(e){setTimeout(function(){throw e},0)}o=!1}catch(e){return o=!0,void(r.error&&r.error(new y({networkError:e})))}}}}}},e.prototype.watchQuery=function(e,t){if(void 0===t&&(t=!0),"standby"===e.fetchPolicy)throw new Error('client.watchQuery cannot be called with fetchPolicy set to "standby"');var r=Object(_.k)(e.query);if(r.variableDefinitions&&r.variableDefinitions.length){var n=Object(_.c)(r);e.variables=Object(I.a)({},n,e.variables)}void 0===e.notifyOnNetworkStatusChange&&(e.notifyOnNetworkStatusChange=!1);var i=Q({},e);return new g({scheduler:this.scheduler,options:i,shouldSubscribe:t})},e.prototype.query=function(e){var t=this;if(!e.query)throw new Error("query option is required. You must specify your GraphQL document in the query option.");if("Document"!==e.query.kind)throw new Error('You must wrap the query string in a "gql" tag.');if(e.returnPartialData)throw new Error("returnPartialData option only supported on watchQuery.");if(e.pollInterval)throw new Error("pollInterval option only supported on watchQuery.");var r=this.idCounter;return new Promise(function(n,i){return t.addFetchQueryPromise(r,n,i),t.watchQuery(e,!1).result().then(function(e){t.removeFetchQueryPromise(r),n(e)}).catch(function(e){t.removeFetchQueryPromise(r),i(e)})})},e.prototype.generateQueryId=function(){var e=this.idCounter.toString();return this.idCounter++,e},e.prototype.stopQueryInStore=function(e){this.queryStore.stopQuery(e),this.invalidate(!0,e),this.broadcastQueries()},e.prototype.addQueryListener=function(e,t){this.setQuery(e,function(e){var r=e.listeners;return{listeners:(void 0===r?[]:r).concat([t]),invalidate:!1}})},e.prototype.updateQueryWatch=function(e,t,r){var n=this,i=this.getQuery(e).cancel;i&&i();return this.dataStore.getCache().watch({query:t,variables:r.variables,optimistic:!0,previousResult:function(){var t=null,r=n.getQuery(e).observableQuery;if(r){var i=r.getLastResult();i&&(t=i.data)}return t},callback:function(t){n.setQuery(e,function(){return{invalidated:!0,newData:t}})}})},e.prototype.addFetchQueryPromise=function(e,t,r){this.fetchQueryPromises.set(e.toString(),{resolve:t,reject:r})},e.prototype.removeFetchQueryPromise=function(e){this.fetchQueryPromises.delete(e.toString())},e.prototype.addObservableQuery=function(e,t){this.setQuery(e,function(){return{observableQuery:t}});var r=Object(_.k)(t.options.query);if(r.name&&r.name.value){var n=r.name.value;this.queryIdsByName[n]=this.queryIdsByName[n]||[],this.queryIdsByName[n].push(t.queryId)}},e.prototype.removeObservableQuery=function(e){var t=this.getQuery(e),r=t.observableQuery,n=t.cancel;if(n&&n(),r){var i=Object(_.k)(r.options.query),o=i.name?i.name.value:null;this.setQuery(e,function(){return{observableQuery:null}}),o&&(this.queryIdsByName[o]=this.queryIdsByName[o].filter(function(e){return!(r.queryId===e)}))}},e.prototype.clearStore=function(){this.fetchQueryPromises.forEach(function(e){(0,e.reject)(new Error("Store reset while query was in flight(not completed in link chain)"))});var e=[];return this.queries.forEach(function(t,r){t.observableQuery&&e.push(r)}),this.queryStore.reset(e),this.mutationStore.reset(),this.dataStore.reset()},e.prototype.resetStore=function(){var e=this;return this.clearStore().then(function(){return e.reFetchObservableQueries()})},e.prototype.reFetchObservableQueries=function(e){var t=this.getObservableQueryPromises(e);return this.broadcastQueries(),Promise.all(t)},e.prototype.startQuery=function(e,t,r){return this.addQueryListener(e,r),this.fetchQuery(e,t).catch(function(){}),e},e.prototype.startGraphQLSubscription=function(e){var t,r=this,n=e.query,i=!(e.fetchPolicy&&"no-cache"===e.fetchPolicy),o=this.dataStore.getCache().transformDocument(n),a=Object(I.a)({},Object(_.c)(Object(_.h)(n)),e.variables),u=[];return new d(function(e){if(u.push(e),1===u.length){var n={next:function(e){i&&(r.dataStore.markSubscriptionResult(e,o,a),r.broadcastQueries()),u.forEach(function(t){t.next&&t.next(e)})},error:function(e){u.forEach(function(t){t.error&&t.error(e)})}},c=r.buildOperationForLink(o,a);t=Object(s.execute)(r.link,c).subscribe(n)}return function(){0===(u=u.filter(function(t){return t!==e})).length&&t&&t.unsubscribe()}})},e.prototype.stopQuery=function(e){this.stopQueryInStore(e),this.removeQuery(e)},e.prototype.removeQuery=function(e){this.getQuery(e).subscriptions.forEach(function(e){return e.unsubscribe()}),this.queries.delete(e)},e.prototype.getCurrentQueryResult=function(e,t){void 0===t&&(t=!0);var r=e.options,n=r.variables,i=r.query,o=e.getLastResult(),u=this.getQuery(e.queryId).newData;if(u)return Object(a.a)({data:u.result,partial:!1});try{var c=this.dataStore.getCache().read({query:i,variables:n,previousResult:o?o.data:void 0,optimistic:t});return Object(a.a)({data:c,partial:!1})}catch(e){return Object(a.a)({data:{},partial:!0})}},e.prototype.getQueryWithPreviousResult=function(e){var t;if("string"==typeof e){var r=this.getQuery(e).observableQuery;if(!r)throw new Error("ObservableQuery with this id doesn't exist: "+e);t=r}else t=e;var n=t.options,i=n.variables,o=n.query;return{previousResult:this.getCurrentQueryResult(t,!1).data,variables:i,document:o}},e.prototype.broadcastQueries=function(){var e=this;this.onBroadcast(),this.queries.forEach(function(t,r){t.invalidated&&t.listeners&&t.listeners.filter(function(e){return!!e}).forEach(function(n){n(e.queryStore.get(r),t.newData)})})},e.prototype.getObservableQueryPromises=function(e){var t=this,r=[];return this.queries.forEach(function(n,i){var o=n.observableQuery;if(o){var a=o.options.fetchPolicy;o.resetLastResults(),"cache-only"===a||!e&&"standby"===a||r.push(o.refetch()),t.setQuery(i,function(){return{newData:null}}),t.invalidate(!0,i)}}),r},e.prototype.fetchRequest=function(e){var t,r,i=this,o=e.requestId,a=e.queryId,u=e.document,c=e.options,l=e.fetchMoreForQueryId,f=c.variables,d=c.context,p=c.errorPolicy,h=void 0===p?"none":p,v=c.fetchPolicy,m=this.buildOperationForLink(u,f,Q({},d,{forceFetch:!this.queryDeduplication}));return new Promise(function(e,c){i.addFetchQueryPromise(o,e,c);var d=Object(s.execute)(i.deduplicator,m).subscribe({next:function(e){var n=i.getQuery(a).lastRequestId;if(o>=(n||1)){if("no-cache"!==v)try{i.dataStore.markQueryResult(e,u,f,l,"ignore"===h||"all"===h)}catch(e){return void c(e)}else i.setQuery(a,function(){return{newData:{result:e.data,complete:!0}}});i.queryStore.markQueryResult(a,e,l),i.invalidate(!0,a,l),i.broadcastQueries()}if(e.errors&&"none"===h)c(new y({graphQLErrors:e.errors}));else if("all"===h&&(r=e.errors),l||"no-cache"===v)t=e.data;else try{t=i.dataStore.getCache().read({variables:f,query:u,optimistic:!1})}catch(e){}},error:function(e){i.removeFetchQueryPromise(o),i.setQuery(a,function(e){return{subscriptions:e.subscriptions.filter(function(e){return e!==d})}}),c(e)},complete:function(){i.removeFetchQueryPromise(o),i.setQuery(a,function(e){return{subscriptions:e.subscriptions.filter(function(e){return e!==d})}}),e({data:t,errors:r,loading:!1,networkStatus:n.ready,stale:!1})}});i.setQuery(a,function(e){return{subscriptions:e.subscriptions.concat([d])}})})},e.prototype.refetchQueryByName=function(e){var t=this,r=this.queryIdsByName[e];if(void 0!==r)return Promise.all(r.map(function(e){return t.getQuery(e).observableQuery}).filter(function(e){return!!e}).map(function(e){return e.refetch()}))},e.prototype.generateRequestId=function(){var e=this.idCounter;return this.idCounter++,e},e.prototype.getQuery=function(e){return this.queries.get(e)||Q({},D)},e.prototype.setQuery=function(e,t){var r=this.getQuery(e),n=Q({},r,t(r));this.queries.set(e,n)},e.prototype.invalidate=function(e,t,r){t&&this.setQuery(t,function(){return{invalidated:e}}),r&&this.setQuery(r,function(){return{invalidated:e}})},e.prototype.buildOperationForLink=function(e,t,r){var n=this.dataStore.getCache();return{query:n.transformForLink?n.transformForLink(e):e,variables:t,operationName:Object(_.j)(e)||void 0,context:Q({},r,{cache:n,getCacheKey:function(e){if(n.config)return n.config.dataIdFromObject(e);throw new Error("To use context.getCacheKey, you need to use a cache that has a configurable dataIdFromObject, like apollo-cache-inmemory.")}})}},e}(),x=function(){function e(e){this.cache=e}return e.prototype.getCache=function(){return this.cache},e.prototype.markQueryResult=function(e,t,r,n,i){void 0===i&&(i=!1);var o=!Object(u.a)(e);i&&Object(u.a)(e)&&e.data&&(o=!0),!n&&o&&this.cache.write({result:e.data,dataId:"ROOT_QUERY",query:t,variables:r})},e.prototype.markSubscriptionResult=function(e,t,r){Object(u.a)(e)||this.cache.write({result:e.data,dataId:"ROOT_SUBSCRIPTION",query:t,variables:r})},e.prototype.markMutationInit=function(e){var t=this;if(e.optimisticResponse){var r;r="function"==typeof e.optimisticResponse?e.optimisticResponse(e.variables):e.optimisticResponse;this.cache.recordOptimisticTransaction(function(n){var i=t.cache;t.cache=n;try{t.markMutationResult({mutationId:e.mutationId,result:{data:r},document:e.document,variables:e.variables,updateQueries:e.updateQueries,update:e.update})}finally{t.cache=i}},e.mutationId)}},e.prototype.markMutationResult=function(e){var t=this;if(!Object(u.a)(e.result)){var r=[];r.push({result:e.result.data,dataId:"ROOT_MUTATION",query:e.document,variables:e.variables}),e.updateQueries&&Object.keys(e.updateQueries).filter(function(t){return e.updateQueries[t]}).forEach(function(n){var i=e.updateQueries[n],o=i.query,a=i.updater,c=t.cache.diff({query:o.document,variables:o.variables,returnPartialData:!0,optimistic:!1}),s=c.result;if(c.complete){var l=Object(u.b)(function(){return a(s,{mutationResult:e.result,queryName:Object(_.j)(o.document)||void 0,queryVariables:o.variables})});l&&r.push({result:l,dataId:"ROOT_QUERY",query:o.document,variables:o.variables})}}),this.cache.performTransaction(function(e){r.forEach(function(t){return e.write(t)})});var n=e.update;n&&this.cache.performTransaction(function(t){Object(u.b)(function(){return n(t,e.result)})})}},e.prototype.markMutationComplete=function(e){var t=e.mutationId;e.optimisticResponse&&this.cache.removeOptimistic(t)},e.prototype.markUpdateQueryResult=function(e,t,r){this.cache.write({result:r,dataId:"ROOT_QUERY",variables:t,query:e})},e.prototype.reset=function(){return this.cache.reset()},e}(),M=r(24),L=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0,this.queryDeduplication=l,this.ssrMode=o,this.defaultOptions=f||{},u&&setTimeout(function(){return t.disableNetworkFetches=!1},u),this.watchQuery=this.watchQuery.bind(this),this.query=this.query.bind(this),this.mutate=this.mutate.bind(this),this.resetStore=this.resetStore.bind(this),this.reFetchObservableQueries=this.reFetchObservableQueries.bind(this);var d=!Object(w.d)()&&"undefined"!=typeof window&&!window.__APOLLO_CLIENT__;(void 0===c?d:c&&"undefined"!=typeof window)&&(window.__APOLLO_CLIENT__=this),C||Object(w.d)()||(C=!0,"undefined"!=typeof window&&window.document&&window.top===window.self&&void 0===window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__&&window.navigator&&window.navigator.userAgent.indexOf("Chrome")>-1&&console.debug("Download the Apollo DevTools for a better development experience: https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm")),this.version=M.version}return e.prototype.watchQuery=function(e){return this.defaultOptions.watchQuery&&(e=L({},this.defaultOptions.watchQuery,e)),!this.disableNetworkFetches||"network-only"!==e.fetchPolicy&&"cache-and-network"!==e.fetchPolicy||(e=L({},e,{fetchPolicy:"cache-first"})),this.initQueryManager().watchQuery(e)},e.prototype.query=function(e){if(this.defaultOptions.query&&(e=L({},this.defaultOptions.query,e)),"cache-and-network"===e.fetchPolicy)throw new Error("cache-and-network fetchPolicy can only be used with watchQuery");return this.disableNetworkFetches&&"network-only"===e.fetchPolicy&&(e=L({},e,{fetchPolicy:"cache-first"})),this.initQueryManager().query(e)},e.prototype.mutate=function(e){return this.defaultOptions.mutate&&(e=L({},this.defaultOptions.mutate,e)),this.initQueryManager().mutate(e)},e.prototype.subscribe=function(e){return this.initQueryManager().startGraphQLSubscription(e)},e.prototype.readQuery=function(e){return this.initProxy().readQuery(e)},e.prototype.readFragment=function(e){return this.initProxy().readFragment(e)},e.prototype.writeQuery=function(e){var t=this.initProxy().writeQuery(e);return this.initQueryManager().broadcastQueries(),t},e.prototype.writeFragment=function(e){var t=this.initProxy().writeFragment(e);return this.initQueryManager().broadcastQueries(),t},e.prototype.writeData=function(e){var t=this.initProxy().writeData(e);return this.initQueryManager().broadcastQueries(),t},e.prototype.__actionHookForDevTools=function(e){this.devToolsHookCb=e},e.prototype.__requestRaw=function(e){return Object(s.execute)(this.link,e)},e.prototype.initQueryManager=function(){var e=this;return this.queryManager||(this.queryManager=new A({link:this.link,store:this.store,queryDeduplication:this.queryDeduplication,ssrMode:this.ssrMode,onBroadcast:function(){e.devToolsHookCb&&e.devToolsHookCb({action:{},state:{queries:e.queryManager?e.queryManager.queryStore.getStore():{},mutations:e.queryManager?e.queryManager.mutationStore.getStore():{}},dataWithOptimisticResults:e.cache.extract(!0)})}})),this.queryManager},e.prototype.resetStore=function(){var e=this;return Promise.resolve().then(function(){return e.queryManager?e.queryManager.clearStore():Promise.resolve(null)}).then(function(){return Promise.all(e.resetStoreCallbacks.map(function(e){return e()}))}).then(function(){return e.queryManager&&e.queryManager.reFetchObservableQueries?e.queryManager.reFetchObservableQueries():Promise.resolve(null)})},e.prototype.onResetStore=function(e){var t=this;return this.resetStoreCallbacks.push(e),function(){t.resetStoreCallbacks=t.resetStoreCallbacks.filter(function(t){return t!==e})}},e.prototype.reFetchObservableQueries=function(e){return this.queryManager?this.queryManager.reFetchObservableQueries(e):Promise.resolve(null)},e.prototype.extract=function(e){return this.initProxy().extract(e)},e.prototype.restore=function(e){return this.initProxy().restore(e)},e.prototype.initProxy=function(){return this.proxy||(this.initQueryManager(),this.proxy=this.cache),this.proxy},e}();r.d(t,"printAST",function(){return i.a}),r.d(t,"ObservableQuery",function(){return g}),r.d(t,"NetworkStatus",function(){return n}),r.d(t,"FetchType",function(){return h}),r.d(t,"ApolloError",function(){return y}),r.d(t,"ApolloClient",function(){return B});t.default=B},function(e,t,r){"use strict";r.r(t);var n=r(16);function i(e){if("number"==typeof e||"boolean"==typeof e||"string"==typeof e||void 0===e||null===e)return null;if(Array.isArray(e))return i(e[0]);var t=[];return Object.keys(e).forEach(function(r){var n={kind:"Field",name:{kind:"Name",value:r}},o=i(e[r]);o&&(n.selectionSet=o),t.push(n)}),{kind:"SelectionSet",selections:t}}var o={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"query",name:null,variableDefinitions:null,directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",alias:null,name:{kind:"Name",value:"__typename"},arguments:[],directives:[],selectionSet:null}]}}]},a=function(){function e(){}return e.prototype.transformDocument=function(e){return e},e.prototype.transformForLink=function(e){return e},e.prototype.readQuery=function(e,t){return void 0===t&&(t=!1),this.read({query:e.query,variables:e.variables,optimistic:t})},e.prototype.readFragment=function(e,t){return void 0===t&&(t=!1),this.read({query:Object(n.a)(e.fragment,e.fragmentName),variables:e.variables,rootId:e.id,optimistic:t})},e.prototype.writeQuery=function(e){this.write({dataId:"ROOT_QUERY",result:e.data,query:e.query,variables:e.variables})},e.prototype.writeFragment=function(e){this.write({dataId:e.id,result:e.data,variables:e.variables,query:Object(n.a)(e.fragment,e.fragmentName)})},e.prototype.writeData=function(e){var t=e.id,r=e.data;if(void 0!==t){var n=null;try{n=this.read({rootId:t,optimistic:!1,query:o})}catch(e){}var a=n&&n.__typename||"__ClientData",u=Object.assign({__typename:a},r);this.writeFragment({id:t,fragment:function(e,t){return{kind:"Document",definitions:[{kind:"FragmentDefinition",typeCondition:{kind:"NamedType",name:{kind:"Name",value:t||"__FakeType"}},name:{kind:"Name",value:"GeneratedClientQuery"},selectionSet:i(e)}]}}(u,a),data:u})}else this.writeQuery({query:function(e){return{kind:"Document",definitions:[{kind:"OperationDefinition",operation:"query",name:{kind:"Name",value:"GeneratedClientQuery"},selectionSet:i(e)}]}}(r),data:r})},e}(),u=r(13),c=r(3),s=r(15),l=!1,f=function(){function e(){}return e.prototype.ensureReady=function(){return Promise.resolve()},e.prototype.canBypassInit=function(){return!0},e.prototype.match=function(e,t,r){var n=r.store.get(e.id);return!n&&"ROOT_QUERY"===e.id||!!n&&(n.__typename?n.__typename===t||(Object(s.a)("You are using the simple (heuristic) fragment matcher, but your queries contain union or interface types.\n Apollo Client will not be able to able to accurately map fragments.To make this error go away, use the IntrospectionFragmentMatcher as described in the docs: https://www.apollographql.com/docs/react/recipes/fragment-matching.html","error"),r.returnPartialData=!0,!0):(l||(console.warn("You're using fragments in your queries, but either don't have the addTypename:\n true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.\n Please turn on the addTypename option and include __typename when writing fragments so that Apollo Client\n can accurately match fragments."),console.warn("Could not find __typename on Fragment ",t,n),console.warn("DEPRECATION WARNING: using fragments without __typename is unsupported behavior and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now."),Object(c.e)()||(l=!0)),r.returnPartialData=!0,!0))},e}(),d=function(){function e(e){e&&e.introspectionQueryResultData?(this.possibleTypesMap=this.parseIntrospectionResult(e.introspectionQueryResultData),this.isReady=!0):this.isReady=!1,this.match=this.match.bind(this)}return e.prototype.match=function(e,t,r){if(!this.isReady)throw new Error("FragmentMatcher.match() was called before FragmentMatcher.init()");var n=r.store.get(e.id);if(!n)return!1;if(!n.__typename)throw new Error("Cannot match fragment because __typename property is missing: "+JSON.stringify(n));if(n.__typename===t)return!0;var i=this.possibleTypesMap[t];return!!(i&&i.indexOf(n.__typename)>-1)},e.prototype.parseIntrospectionResult=function(e){var t={};return e.__schema.types.forEach(function(e){"UNION"!==e.kind&&"INTERFACE"!==e.kind||(t[e.name]=e.possibleTypes.map(function(e){return e.name}))}),t},e}(),p=r(2),h=r(6),v=r(7),y=r(14),m=r(4),b=function(){function e(e){void 0===e&&(e=Object.create(null)),this.data=e}return e.prototype.toObject=function(){return this.data},e.prototype.get=function(e){return this.data[e]},e.prototype.set=function(e,t){this.data[e]=t},e.prototype.delete=function(e){this.data[e]=void 0},e.prototype.clear=function(){this.data=Object.create(null)},e.prototype.replace=function(e){this.data=e||Object.create(null)},e}();function g(e){return new b(e)}var O=function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),w=Object.assign||function(e){for(var t,r=1,n=arguments.length;r=0)return!0;r[e].push(t)}else r[e]=[t];return!1}function j(e,t,r){var n=r.fragmentMap,i=r.contextValue,o=r.variableValues,a={};return e.selections.forEach(function(e){if(Object(y.e)(e,o))if(Object(m.c)(e)){var u=function(e,t,r){var n=r.variableValues,i=r.contextValue,o=r.resolver,a=e.name.value,u=Object(m.a)(e,n),c={isLeaf:!e.selectionSet,resultKey:Object(m.i)(e),directives:Object(y.b)(e,n)},s=o(a,t,u,i,c);if(!e.selectionSet)return s;if(null==s)return s;if(Array.isArray(s))return function e(t,r,n){return r.map(function(r){return null===r?null:Array.isArray(r)?e(t,r,n):j(t.selectionSet,r,n)})}(e,s,r);return j(e.selectionSet,s,r)}(e,t,r),c=Object(m.i)(e);void 0!==u&&(void 0===a[c]?a[c]=u:F(a[c],u))}else{var s=void 0;if(Object(m.e)(e))s=e;else if(!(s=n[e.name.value]))throw new Error("No fragment named "+e.name.value);var l=s.typeCondition.name.value;if(r.fragmentMatcher(t,l,i)){var f=j(s.selectionSet,t,r);F(a,f)}}}),r.resultMapper?r.resultMapper(a,t):a}var P=Object.prototype.hasOwnProperty;function F(e,t){null!==t&&"object"==typeof t&&Object.keys(t).forEach(function(r){var n=t[r];P.call(e,r)?F(e[r],n):e[r]=n})}var Q=function(e,t,r,n,i,o){void 0===o&&(o={});var a=Object(h.f)(t),u=Object(h.e)(t),c={fragmentMap:Object(h.b)(u),contextValue:n,variableValues:i,resultMapper:o.resultMapper,resolver:e,fragmentMatcher:o.fragmentMatcher||function(){return!0}};return j(a.selectionSet,r,c)},R=r(10),q=Object.assign||function(e){for(var t,r=1,n=arguments.length;r-1})&&r.every(function(r){return function e(t,r){if(t===r)return!0;if(!Array.isArray(t)||!Array.isArray(r)||t.length!==r.length)return!1;return t.every(function(t,n){return e(t,r[n])})}(e[r],t.previousResult[r])}))return t.previousResult}return Object.defineProperty(e,D,{enumerable:!1,configurable:!0,writable:!1,value:t.id}),e}var V=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0){var t=this.optimistic.map(function(e){return e.data});return Object.assign.apply(Object,[{},this.data.toObject()].concat(t))}return this.data.toObject()},t.prototype.read=function(e){return e.rootId&&void 0===this.data.get(e.rootId)?null:A({store:this.config.storeFactory(this.extract(e.optimistic)),query:this.transformDocument(e.query),variables:e.variables,rootId:e.rootId,fragmentMatcherFunction:this.config.fragmentMatcher.match,previousResult:e.previousResult,config:this.config})},t.prototype.write=function(e){_({dataId:e.dataId,result:e.result,variables:e.variables,document:this.transformDocument(e.query),store:this.data,dataIdFromObject:this.config.dataIdFromObject,fragmentMatcherFunction:this.config.fragmentMatcher.match}),this.broadcastWatches()},t.prototype.diff=function(e){return M({store:this.config.storeFactory(this.extract(e.optimistic)),query:this.transformDocument(e.query),variables:e.variables,returnPartialData:e.returnPartialData,previousResult:e.previousResult,fragmentMatcherFunction:this.config.fragmentMatcher.match,config:this.config})},t.prototype.watch=function(e){var t=this;return this.watches.push(e),function(){t.watches=t.watches.filter(function(t){return t!==e})}},t.prototype.evict=function(e){throw new Error("eviction is not implemented on InMemory Cache")},t.prototype.reset=function(){return this.data.clear(),this.broadcastWatches(),Promise.resolve()},t.prototype.removeOptimistic=function(e){var t=this,r=this.optimistic.filter(function(t){return t.id!==e});this.optimistic=[],r.forEach(function(e){t.recordOptimisticTransaction(e.transaction,e.id)}),this.broadcastWatches()},t.prototype.performTransaction=function(e){var t=this.silenceBroadcast;this.silenceBroadcast=!0,e(this),t||(this.silenceBroadcast=!1),this.broadcastWatches()},t.prototype.recordOptimisticTransaction=function(e,t){var r=this;this.silenceBroadcast=!0;var n=U(this.extract(!0),function(t){var n=r.data;r.data=t,r.performTransaction(e),r.data=n});this.optimistic.push({id:t,transaction:e,data:n}),this.silenceBroadcast=!1,this.broadcastWatches()},t.prototype.transformDocument=function(e){if(this.addTypename){var t=this.typenameDocumentCache.get(e);return t||this.typenameDocumentCache.set(e,t=Object(u.a)(e)),t}return e},t.prototype.readQuery=function(e,t){return void 0===t&&(t=!1),this.read({query:e.query,variables:e.variables,optimistic:t})},t.prototype.readFragment=function(e,t){return void 0===t&&(t=!1),this.read({query:this.transformDocument(Object(n.a)(e.fragment,e.fragmentName)),variables:e.variables,rootId:e.id,optimistic:t})},t.prototype.writeQuery=function(e){this.write({dataId:"ROOT_QUERY",result:e.data,query:this.transformDocument(e.query),variables:e.variables})},t.prototype.writeFragment=function(e){this.write({dataId:e.id,result:e.data,query:this.transformDocument(Object(n.a)(e.fragment,e.fragmentName)),variables:e.variables})},t.prototype.broadcastWatches=function(){var e=this;this.silenceBroadcast||this.watches.forEach(function(t){var r=e.diff({query:t.query,variables:t.variables,previousResult:t.previousResult&&t.previousResult(),optimistic:t.optimistic});t.callback(r)})},t}(a);r.d(t,"InMemoryCache",function(){return H}),r.d(t,"defaultDataIdFromObject",function(){return K}),r.d(t,"ID_KEY",function(){return D}),r.d(t,"readQueryFromStore",function(){return A}),r.d(t,"diffQueryAgainstStore",function(){return M}),r.d(t,"assertIdValue",function(){return L}),r.d(t,"WriteError",function(){return E}),r.d(t,"enhanceErrorWithDocument",function(){return k}),r.d(t,"writeQueryToStore",function(){return I}),r.d(t,"writeResultToStore",function(){return _}),r.d(t,"writeSelectionSetToStore",function(){return T}),r.d(t,"HeuristicFragmentMatcher",function(){return f}),r.d(t,"IntrospectionFragmentMatcher",function(){return d}),r.d(t,"ObjectCache",function(){return b}),r.d(t,"defaultNormalizedCacheFactory",function(){return g}),r.d(t,"RecordingCache",function(){return B}),r.d(t,"record",function(){return U})},function(e,t,r){"use strict";var n=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),i=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&console.warn("ApolloBoost was initialized with unsupported options: "+r.join(" "))}var n=t.request,o=t.uri,f=t.credentials,p=t.headers,h=t.fetch,v=t.fetchOptions,y=t.clientState,m=t.cacheRedirects,b=t.onError,g=t.cache;if(g&&m)throw new Error("Incompatible cache configuration. If providing `cache` then configure the provided instance with `cacheRedirects` instead.");g||(g=m?new l.InMemoryCache({cacheRedirects:m}):new l.InMemoryCache);var O=!!y&&c.withClientState(i({},y,{cache:g})),w=b?s.onError(b):s.onError(function(e){var t=e.graphQLErrors,r=e.networkError;t&&t.map(function(e){var t=e.message,r=e.locations,n=e.path;return console.log("[GraphQL error]: Message: "+t+", Location: "+r+", Path: "+n)}),r&&console.log("[Network error]: "+r)}),E=!!n&&new a.ApolloLink(function(e,t){return new a.Observable(function(r){var i;return Promise.resolve(e).then(function(e){return n(e)}).then(function(){i=t(e).subscribe({next:r.next.bind(r),error:r.error.bind(r),complete:r.complete.bind(r)})}).catch(r.error.bind(r)),function(){i&&i.unsubscribe()}})}),k=new u.HttpLink({uri:o||"/graphql",fetch:h,fetchOptions:v||{},credentials:f||"same-origin",headers:p||{}}),I=a.ApolloLink.from([w,E,O,k].filter(function(e){return!!e}));return e.call(this,{cache:g,link:I})||this}return n(t,e),t}(r(17).default);t.default=p},function(e,t,r){e.exports=r(28).Observable},function(e,t,r){"use strict";e.exports=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var r="boolean"==typeof t.cycles&&t.cycles,n=t.cmp&&function(e){return function(t){return function(r,n){var i={key:r,value:t[r]},o={key:n,value:t[n]};return e(i,o)}}}(t.cmp),i=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var o,a;if(Array.isArray(t)){for(a="[",o=0;o0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]{e.data.posts.forEach(e=>l(s,e))});const l=(e,t)=>{const r=document.createElement("section"),n=`\n

\n Post: ${t.title}\n

\n

\n Author: ${t.author.firstName}\n

\n `;r.innerHTML=n,e.appendChild(r)}},function(e,t){var r,n,i=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch(e){r=o}try{n="function"==typeof clearTimeout?clearTimeout:a}catch(e){n=a}}();var c,s=[],l=!1,f=-1;function d(){l&&c&&(l=!1,c.length?s=c.concat(s):f=-1,s.length&&p())}function p(){if(!l){var e=u(d);l=!0;for(var t=s.length;t;){for(c=s,s=[];++f1)for(var r=1;r1,i=!1,o=arguments[1];return new r(function(r){return t.subscribe({next:function(t){var a=!i;if(i=!0,!a||n)try{o=e(o,t)}catch(e){return r.error(e)}else o=t},error:function(e){r.error(e)},complete:function(){if(!i&&!n)return r.error(new TypeError("Cannot reduce an empty sequence"));r.next(o),r.complete()}})})}},{key:"concat",value:function(){for(var e=this,t=arguments.length,r=Array(t),n=0;n=0&&i.splice(e,1),a()}});i.push(o)},error:function(e){n.error(e)},complete:function(){a()}});function a(){o.closed&&0===i.length&&n.complete()}return function(){i.forEach(function(e){return e.unsubscribe()}),o.unsubscribe()}})}},{key:u("observable"),value:function(){return this}}],[{key:"from",value:function(t){var r="function"==typeof this?this:e;if(null==t)throw new TypeError(t+" is not an object");var n=c(t,u("observable"));if(n){var i=n.call(t);if(Object(i)!==i)throw new TypeError(i+" is not an object");return l(i)&&i.constructor===r?i:new r(function(e){return i.subscribe(e)})}if(a("iterator")&&(n=c(t,u("iterator"))))return new r(function(e){d(function(){if(!e.closed){var r=!0,i=!1,o=void 0;try{for(var a,u=n.call(t)[Symbol.iterator]();!(r=(a=u.next()).done);r=!0){var c=a.value;if(e.next(c),e.closed)return}}catch(e){i=!0,o=e}finally{try{!r&&u.return&&u.return()}finally{if(i)throw o}}e.complete()}})});if(Array.isArray(t))return new r(function(e){d(function(){if(!e.closed){for(var r=0;r0||n(0,"line in locationOffset is 1-indexed and must be positive"),this.locationOffset.column>0||n(0,"column in locationOffset is 1-indexed and must be positive")};function o(e,t){for(var r=/\r\n|[\n\r]/g,n=1,i=t+1,o=void 0;(o=r.exec(e.body))&&o.index=2&&c(d,s)+": "+p[r-2],c(d,l)+": "+p[r-1],u(2+d+a-1)+"^",r0&&p(t[0]);)t.shift();for(;t.length>0&&p(t[t.length-1]);)t.pop();return t.join("\n")}function d(e){for(var t=0;t",EOF:"",BANG:"!",DOLLAR:"$",AMP:"&",PAREN_L:"(",PAREN_R:")",SPREAD:"...",COLON:":",EQUALS:"=",AT:"@",BRACKET_L:"[",BRACKET_R:"]",BRACE_L:"{",PIPE:"|",BRACE_R:"}",NAME:"Name",INT:"Int",FLOAT:"Float",STRING:"String",BLOCK_STRING:"BlockString",COMMENT:"Comment"});function b(e){var t=e.value;return t?e.kind+' "'+t+'"':e.kind}var g=String.prototype.charCodeAt,O=String.prototype.slice;function w(e,t,r,n,i,o,a){this.kind=e,this.start=t,this.end=r,this.line=n,this.column=i,this.value=a,this.prev=o,this.next=null}function E(e){return isNaN(e)?m.EOF:e<127?JSON.stringify(String.fromCharCode(e)):'"\\u'+("00"+e.toString(16).toUpperCase()).slice(-4)+'"'}function k(e,t){var r=e.source,n=r.body,i=n.length,o=function(e,t,r){var n=e.length,i=t;for(;i=i)return new w(m.EOF,i,i,a,u,t);var c=g.call(n,o);if(c<32&&9!==c&&10!==c&&13!==c)throw l(r,o,"Cannot contain the invalid character "+E(c)+".");switch(c){case 33:return new w(m.BANG,o,o+1,a,u,t);case 35:return function(e,t,r,n,i){var o=e.body,a=void 0,u=t;do{a=g.call(o,++u)}while(null!==a&&(a>31||9===a));return new w(m.COMMENT,t,u,r,n,i,O.call(o,t+1,u))}(r,o,a,u,t);case 36:return new w(m.DOLLAR,o,o+1,a,u,t);case 38:return new w(m.AMP,o,o+1,a,u,t);case 40:return new w(m.PAREN_L,o,o+1,a,u,t);case 41:return new w(m.PAREN_R,o,o+1,a,u,t);case 46:if(46===g.call(n,o+1)&&46===g.call(n,o+2))return new w(m.SPREAD,o,o+3,a,u,t);break;case 58:return new w(m.COLON,o,o+1,a,u,t);case 61:return new w(m.EQUALS,o,o+1,a,u,t);case 64:return new w(m.AT,o,o+1,a,u,t);case 91:return new w(m.BRACKET_L,o,o+1,a,u,t);case 93:return new w(m.BRACKET_R,o,o+1,a,u,t);case 123:return new w(m.BRACE_L,o,o+1,a,u,t);case 124:return new w(m.PIPE,o,o+1,a,u,t);case 125:return new w(m.BRACE_R,o,o+1,a,u,t);case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:case 79:case 80:case 81:case 82:case 83:case 84:case 85:case 86:case 87:case 88:case 89:case 90:case 95:case 97:case 98:case 99:case 100:case 101:case 102:case 103:case 104:case 105:case 106:case 107:case 108:case 109:case 110:case 111:case 112:case 113:case 114:case 115:case 116:case 117:case 118:case 119:case 120:case 121:case 122:return function(e,t,r,n,i){var o=e.body,a=o.length,u=t+1,c=0;for(;u!==a&&null!==(c=g.call(o,u))&&(95===c||c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122);)++u;return new w(m.NAME,t,u,r,n,i,O.call(o,t,u))}(r,o,a,u,t);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return function(e,t,r,n,i,o){var a=e.body,u=r,c=t,s=!1;45===u&&(u=g.call(a,++c));if(48===u){if((u=g.call(a,++c))>=48&&u<=57)throw l(e,c,"Invalid number, unexpected digit after 0: "+E(u)+".")}else c=I(e,c,u),u=g.call(a,c);46===u&&(s=!0,u=g.call(a,++c),c=I(e,c,u),u=g.call(a,c));69!==u&&101!==u||(s=!0,43!==(u=g.call(a,++c))&&45!==u||(u=g.call(a,++c)),c=I(e,c,u));return new w(s?m.FLOAT:m.INT,t,c,n,i,o,O.call(a,t,c))}(r,o,c,a,u,t);case 34:return 34===g.call(n,o+1)&&34===g.call(n,o+2)?function(e,t,r,n,i){var o=e.body,a=t+3,u=a,c=0,s="";for(;a=48&&o<=57){do{o=g.call(n,++i)}while(o>=48&&o<=57);return i}throw l(e,i,"Invalid number, expected digit but got: "+E(o)+".")}function _(e,t,r,n){return T(e)<<12|T(t)<<8|T(r)<<4|T(n)}function T(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:-1}w.prototype.toJSON=w.prototype.inspect=function(){return{kind:this.kind,value:this.value,line:this.line,column:this.column}};var N=Object.freeze({NAME:"Name",DOCUMENT:"Document",OPERATION_DEFINITION:"OperationDefinition",VARIABLE_DEFINITION:"VariableDefinition",VARIABLE:"Variable",SELECTION_SET:"SelectionSet",FIELD:"Field",ARGUMENT:"Argument",FRAGMENT_SPREAD:"FragmentSpread",INLINE_FRAGMENT:"InlineFragment",FRAGMENT_DEFINITION:"FragmentDefinition",INT:"IntValue",FLOAT:"FloatValue",STRING:"StringValue",BOOLEAN:"BooleanValue",NULL:"NullValue",ENUM:"EnumValue",LIST:"ListValue",OBJECT:"ObjectValue",OBJECT_FIELD:"ObjectField",DIRECTIVE:"Directive",NAMED_TYPE:"NamedType",LIST_TYPE:"ListType",NON_NULL_TYPE:"NonNullType",SCHEMA_DEFINITION:"SchemaDefinition",OPERATION_TYPE_DEFINITION:"OperationTypeDefinition",SCALAR_TYPE_DEFINITION:"ScalarTypeDefinition",OBJECT_TYPE_DEFINITION:"ObjectTypeDefinition",FIELD_DEFINITION:"FieldDefinition",INPUT_VALUE_DEFINITION:"InputValueDefinition",INTERFACE_TYPE_DEFINITION:"InterfaceTypeDefinition",UNION_TYPE_DEFINITION:"UnionTypeDefinition",ENUM_TYPE_DEFINITION:"EnumTypeDefinition",ENUM_VALUE_DEFINITION:"EnumValueDefinition",INPUT_OBJECT_TYPE_DEFINITION:"InputObjectTypeDefinition",SCALAR_TYPE_EXTENSION:"ScalarTypeExtension",OBJECT_TYPE_EXTENSION:"ObjectTypeExtension",INTERFACE_TYPE_EXTENSION:"InterfaceTypeExtension",UNION_TYPE_EXTENSION:"UnionTypeExtension",ENUM_TYPE_EXTENSION:"EnumTypeExtension",INPUT_OBJECT_TYPE_EXTENSION:"InputObjectTypeExtension",DIRECTIVE_DEFINITION:"DirectiveDefinition"}),S=Object.freeze({QUERY:"QUERY",MUTATION:"MUTATION",SUBSCRIPTION:"SUBSCRIPTION",FIELD:"FIELD",FRAGMENT_DEFINITION:"FRAGMENT_DEFINITION",FRAGMENT_SPREAD:"FRAGMENT_SPREAD",INLINE_FRAGMENT:"INLINE_FRAGMENT",SCHEMA:"SCHEMA",SCALAR:"SCALAR",OBJECT:"OBJECT",FIELD_DEFINITION:"FIELD_DEFINITION",ARGUMENT_DEFINITION:"ARGUMENT_DEFINITION",INTERFACE:"INTERFACE",UNION:"UNION",ENUM:"ENUM",ENUM_VALUE:"ENUM_VALUE",INPUT_OBJECT:"INPUT_OBJECT",INPUT_FIELD_DEFINITION:"INPUT_FIELD_DEFINITION"});function j(e,t){var r="string"==typeof e?new i(e):e;if(!(r instanceof i))throw new TypeError("Must provide Source. Received: "+String(r));return function(e){var t=e.token;ge(e,m.SOF);var r=[];do{r.push(R(e))}while(!be(e,m.EOF));return{kind:N.DOCUMENT,definitions:r,loc:ve(e,t)}}(h(r,t||{}))}function P(e,t){var r=h("string"==typeof e?new i(e):e,t||{});ge(r,m.SOF);var n=J(r,!1);return ge(r,m.EOF),n}function F(e,t){var r=h("string"==typeof e?new i(e):e,t||{});ge(r,m.SOF);var n=Z(r);return ge(r,m.EOF),n}function Q(e){var t=ge(e,m.NAME);return{kind:N.NAME,value:t.value,loc:ve(e,t)}}function R(e){if(me(e,m.NAME))switch(e.token.value){case"query":case"mutation":case"subscription":case"fragment":return q(e);case"schema":case"scalar":case"type":case"interface":case"union":case"enum":case"input":case"extend":case"directive":return te(e)}else{if(me(e,m.BRACE_L))return q(e);if(re(e))return te(e)}throw we(e)}function q(e){if(me(e,m.NAME))switch(e.token.value){case"query":case"mutation":case"subscription":return D(e);case"fragment":return function(e){var t=e.token;if(Oe(e,"fragment"),e.options.experimentalFragmentVariables)return{kind:N.FRAGMENT_DEFINITION,name:Y(e),variableDefinitions:x(e),typeCondition:(Oe(e,"on"),ee(e)),directives:X(e,!1),selectionSet:C(e),loc:ve(e,t)};return{kind:N.FRAGMENT_DEFINITION,name:Y(e),typeCondition:(Oe(e,"on"),ee(e)),directives:X(e,!1),selectionSet:C(e),loc:ve(e,t)}}(e)}else if(me(e,m.BRACE_L))return D(e);throw we(e)}function D(e){var t=e.token;if(me(e,m.BRACE_L))return{kind:N.OPERATION_DEFINITION,operation:"query",name:void 0,variableDefinitions:[],directives:[],selectionSet:C(e),loc:ve(e,t)};var r=A(e),n=void 0;return me(e,m.NAME)&&(n=Q(e)),{kind:N.OPERATION_DEFINITION,operation:r,name:n,variableDefinitions:x(e),directives:X(e,!1),selectionSet:C(e),loc:ve(e,t)}}function A(e){var t=ge(e,m.NAME);switch(t.value){case"query":return"query";case"mutation":return"mutation";case"subscription":return"subscription"}throw we(e,t)}function x(e){return me(e,m.PAREN_L)?Ee(e,m.PAREN_L,M,m.PAREN_R):[]}function M(e){var t=e.token;return{kind:N.VARIABLE_DEFINITION,variable:L(e),type:(ge(e,m.COLON),Z(e)),defaultValue:be(e,m.EQUALS)?J(e,!0):void 0,loc:ve(e,t)}}function L(e){var t=e.token;return ge(e,m.DOLLAR),{kind:N.VARIABLE,name:Q(e),loc:ve(e,t)}}function C(e){var t=e.token;return{kind:N.SELECTION_SET,selections:Ee(e,m.BRACE_L,V,m.BRACE_R),loc:ve(e,t)}}function V(e){return me(e,m.SPREAD)?function(e){var t=e.token;if(ge(e,m.SPREAD),me(e,m.NAME)&&"on"!==e.token.value)return{kind:N.FRAGMENT_SPREAD,name:Y(e),directives:X(e,!1),loc:ve(e,t)};var r=void 0;"on"===e.token.value&&(e.advance(),r=ee(e));return{kind:N.INLINE_FRAGMENT,typeCondition:r,directives:X(e,!1),selectionSet:C(e),loc:ve(e,t)}}(e):function(e){var t=e.token,r=Q(e),n=void 0,i=void 0;be(e,m.COLON)?(n=r,i=Q(e)):i=r;return{kind:N.FIELD,alias:n,name:i,arguments:B(e,!1),directives:X(e,!1),selectionSet:me(e,m.BRACE_L)?C(e):void 0,loc:ve(e,t)}}(e)}function B(e,t){var r=t?G:U;return me(e,m.PAREN_L)?Ee(e,m.PAREN_L,r,m.PAREN_R):[]}function U(e){var t=e.token;return{kind:N.ARGUMENT,name:Q(e),value:(ge(e,m.COLON),J(e,!1)),loc:ve(e,t)}}function G(e){var t=e.token;return{kind:N.ARGUMENT,name:Q(e),value:(ge(e,m.COLON),H(e)),loc:ve(e,t)}}function Y(e){if("on"===e.token.value)throw we(e);return Q(e)}function J(e,t){var r=e.token;switch(r.kind){case m.BRACKET_L:return function(e,t){var r=e.token,n=t?H:W;return{kind:N.LIST,values:function(e,t,r,n){ge(e,t);var i=[];for(;!be(e,n);)i.push(r(e));return i}(e,m.BRACKET_L,n,m.BRACKET_R),loc:ve(e,r)}}(e,t);case m.BRACE_L:return function(e,t){var r=e.token;ge(e,m.BRACE_L);var n=[];for(;!be(e,m.BRACE_R);)n.push(z(e,t));return{kind:N.OBJECT,fields:n,loc:ve(e,r)}}(e,t);case m.INT:return e.advance(),{kind:N.INT,value:r.value,loc:ve(e,r)};case m.FLOAT:return e.advance(),{kind:N.FLOAT,value:r.value,loc:ve(e,r)};case m.STRING:case m.BLOCK_STRING:return K(e);case m.NAME:return"true"===r.value||"false"===r.value?(e.advance(),{kind:N.BOOLEAN,value:"true"===r.value,loc:ve(e,r)}):"null"===r.value?(e.advance(),{kind:N.NULL,loc:ve(e,r)}):(e.advance(),{kind:N.ENUM,value:r.value,loc:ve(e,r)});case m.DOLLAR:if(!t)return L(e)}throw we(e)}function K(e){var t=e.token;return e.advance(),{kind:N.STRING,value:t.value,block:t.kind===m.BLOCK_STRING,loc:ve(e,t)}}function H(e){return J(e,!0)}function W(e){return J(e,!1)}function z(e,t){var r=e.token;return{kind:N.OBJECT_FIELD,name:Q(e),value:(ge(e,m.COLON),J(e,t)),loc:ve(e,r)}}function X(e,t){for(var r=[];me(e,m.AT);)r.push($(e,t));return r}function $(e,t){var r=e.token;return ge(e,m.AT),{kind:N.DIRECTIVE,name:Q(e),arguments:B(e,t),loc:ve(e,r)}}function Z(e){var t=e.token,r=void 0;return be(e,m.BRACKET_L)?(r=Z(e),ge(e,m.BRACKET_R),r={kind:N.LIST_TYPE,type:r,loc:ve(e,t)}):r=ee(e),be(e,m.BANG)?{kind:N.NON_NULL_TYPE,type:r,loc:ve(e,t)}:r}function ee(e){var t=e.token;return{kind:N.NAMED_TYPE,name:Q(e),loc:ve(e,t)}}function te(e){var t=re(e)?e.lookahead():e.token;if(t.kind===m.NAME)switch(t.value){case"schema":return function(e){var t=e.token;Oe(e,"schema");var r=X(e,!0),n=Ee(e,m.BRACE_L,ie,m.BRACE_R);return{kind:N.SCHEMA_DEFINITION,directives:r,operationTypes:n,loc:ve(e,t)}}(e);case"scalar":return function(e){var t=e.token,r=ne(e);Oe(e,"scalar");var n=Q(e),i=X(e,!0);return{kind:N.SCALAR_TYPE_DEFINITION,description:r,name:n,directives:i,loc:ve(e,t)}}(e);case"type":return function(e){var t=e.token,r=ne(e);Oe(e,"type");var n=Q(e),i=oe(e),o=X(e,!0),a=ae(e);return{kind:N.OBJECT_TYPE_DEFINITION,description:r,name:n,interfaces:i,directives:o,fields:a,loc:ve(e,t)}}(e);case"interface":return function(e){var t=e.token,r=ne(e);Oe(e,"interface");var n=Q(e),i=X(e,!0),o=ae(e);return{kind:N.INTERFACE_TYPE_DEFINITION,description:r,name:n,directives:i,fields:o,loc:ve(e,t)}}(e);case"union":return function(e){var t=e.token,r=ne(e);Oe(e,"union");var n=Q(e),i=X(e,!0),o=le(e);return{kind:N.UNION_TYPE_DEFINITION,description:r,name:n,directives:i,types:o,loc:ve(e,t)}}(e);case"enum":return function(e){var t=e.token,r=ne(e);Oe(e,"enum");var n=Q(e),i=X(e,!0),o=fe(e);return{kind:N.ENUM_TYPE_DEFINITION,description:r,name:n,directives:i,values:o,loc:ve(e,t)}}(e);case"input":return function(e){var t=e.token,r=ne(e);Oe(e,"input");var n=Q(e),i=X(e,!0),o=pe(e);return{kind:N.INPUT_OBJECT_TYPE_DEFINITION,description:r,name:n,directives:i,fields:o,loc:ve(e,t)}}(e);case"extend":return function(e){var t=e.lookahead();if(t.kind===m.NAME)switch(t.value){case"scalar":return function(e){var t=e.token;Oe(e,"extend"),Oe(e,"scalar");var r=Q(e),n=X(e,!0);if(0===n.length)throw we(e);return{kind:N.SCALAR_TYPE_EXTENSION,name:r,directives:n,loc:ve(e,t)}}(e);case"type":return function(e){var t=e.token;Oe(e,"extend"),Oe(e,"type");var r=Q(e),n=oe(e),i=X(e,!0),o=ae(e);if(0===n.length&&0===i.length&&0===o.length)throw we(e);return{kind:N.OBJECT_TYPE_EXTENSION,name:r,interfaces:n,directives:i,fields:o,loc:ve(e,t)}}(e);case"interface":return function(e){var t=e.token;Oe(e,"extend"),Oe(e,"interface");var r=Q(e),n=X(e,!0),i=ae(e);if(0===n.length&&0===i.length)throw we(e);return{kind:N.INTERFACE_TYPE_EXTENSION,name:r,directives:n,fields:i,loc:ve(e,t)}}(e);case"union":return function(e){var t=e.token;Oe(e,"extend"),Oe(e,"union");var r=Q(e),n=X(e,!0),i=le(e);if(0===n.length&&0===i.length)throw we(e);return{kind:N.UNION_TYPE_EXTENSION,name:r,directives:n,types:i,loc:ve(e,t)}}(e);case"enum":return function(e){var t=e.token;Oe(e,"extend"),Oe(e,"enum");var r=Q(e),n=X(e,!0),i=fe(e);if(0===n.length&&0===i.length)throw we(e);return{kind:N.ENUM_TYPE_EXTENSION,name:r,directives:n,values:i,loc:ve(e,t)}}(e);case"input":return function(e){var t=e.token;Oe(e,"extend"),Oe(e,"input");var r=Q(e),n=X(e,!0),i=pe(e);if(0===n.length&&0===i.length)throw we(e);return{kind:N.INPUT_OBJECT_TYPE_EXTENSION,name:r,directives:n,fields:i,loc:ve(e,t)}}(e)}throw we(e,t)}(e);case"directive":return function(e){var t=e.token,r=ne(e);Oe(e,"directive"),ge(e,m.AT);var n=Q(e),i=ce(e);Oe(e,"on");var o=function(e){be(e,m.PIPE);var t=[];do{t.push(he(e))}while(be(e,m.PIPE));return t}(e);return{kind:N.DIRECTIVE_DEFINITION,description:r,name:n,arguments:i,locations:o,loc:ve(e,t)}}(e)}throw we(e,t)}function re(e){return me(e,m.STRING)||me(e,m.BLOCK_STRING)}function ne(e){if(re(e))return K(e)}function ie(e){var t=e.token,r=A(e);ge(e,m.COLON);var n=ee(e);return{kind:N.OPERATION_TYPE_DEFINITION,operation:r,type:n,loc:ve(e,t)}}function oe(e){var t=[];if("implements"===e.token.value){e.advance(),be(e,m.AMP);do{t.push(ee(e))}while(be(e,m.AMP)||e.options.allowLegacySDLImplementsInterfaces&&me(e,m.NAME))}return t}function ae(e){return e.options.allowLegacySDLEmptyFields&&me(e,m.BRACE_L)&&e.lookahead().kind===m.BRACE_R?(e.advance(),e.advance(),[]):me(e,m.BRACE_L)?Ee(e,m.BRACE_L,ue,m.BRACE_R):[]}function ue(e){var t=e.token,r=ne(e),n=Q(e),i=ce(e);ge(e,m.COLON);var o=Z(e),a=X(e,!0);return{kind:N.FIELD_DEFINITION,description:r,name:n,arguments:i,type:o,directives:a,loc:ve(e,t)}}function ce(e){return me(e,m.PAREN_L)?Ee(e,m.PAREN_L,se,m.PAREN_R):[]}function se(e){var t=e.token,r=ne(e),n=Q(e);ge(e,m.COLON);var i=Z(e),o=void 0;be(e,m.EQUALS)&&(o=H(e));var a=X(e,!0);return{kind:N.INPUT_VALUE_DEFINITION,description:r,name:n,type:i,defaultValue:o,directives:a,loc:ve(e,t)}}function le(e){var t=[];if(be(e,m.EQUALS)){be(e,m.PIPE);do{t.push(ee(e))}while(be(e,m.PIPE))}return t}function fe(e){return me(e,m.BRACE_L)?Ee(e,m.BRACE_L,de,m.BRACE_R):[]}function de(e){var t=e.token,r=ne(e),n=Q(e),i=X(e,!0);return{kind:N.ENUM_VALUE_DEFINITION,description:r,name:n,directives:i,loc:ve(e,t)}}function pe(e){return me(e,m.BRACE_L)?Ee(e,m.BRACE_L,se,m.BRACE_R):[]}function he(e){var t=e.token,r=Q(e);if(S.hasOwnProperty(r.value))return r;throw we(e,t)}function ve(e,t){if(!e.options.noLocation)return new ye(t,e.lastToken,e.source)}function ye(e,t,r){this.start=e.start,this.end=t.end,this.startToken=e,this.endToken=t,this.source=r}function me(e,t){return e.token.kind===t}function be(e,t){var r=e.token.kind===t;return r&&e.advance(),r}function ge(e,t){var r=e.token;if(r.kind===t)return e.advance(),r;throw l(e.source,r.start,"Expected "+t+", found "+b(r))}function Oe(e,t){var r=e.token;if(r.kind===m.NAME&&r.value===t)return e.advance(),r;throw l(e.source,r.start,'Expected "'+t+'", found '+b(r))}function we(e,t){var r=t||e.token;return l(e.source,r.start,"Unexpected "+b(r))}function Ee(e,t,r,n){ge(e,t);for(var i=[r(e)];!be(e,n);)i.push(r(e));return i}r.d(t,"parse",function(){return j}),r.d(t,"parseValue",function(){return P}),r.d(t,"parseType",function(){return F}),r.d(t,"parseConstValue",function(){return H}),r.d(t,"parseTypeReference",function(){return Z}),r.d(t,"parseNamedType",function(){return ee}),ye.prototype.toJSON=ye.prototype.inspect=function(){return{start:this.start,end:this.end}}},function(e,t,r){"use strict";r.r(t);var n=r(0),i=r(2),o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r=300&&u(t,r,"Response not successful: Received status code "+t.status),Array.isArray(r)||r.hasOwnProperty("data")||r.hasOwnProperty("errors")||u(t,r,"Server response was missing for query '"+(Array.isArray(e)?e.map(function(e){return e.operationName}):e.operationName)+"'."),r})}}(e)).then(function(e){return r.next(e),r.complete(),e}).catch(function(e){"AbortError"!==e.name&&(e.result&&e.result.errors&&e.result.data&&r.next(e.result),r.error(e))}),function(){t&&t.abort()}})})};var d=function(e){function t(t){return e.call(this,f(t).request)||this}return s(t,e),t}(n.ApolloLink);r.d(t,"createHttpLink",function(){return f}),r.d(t,"HttpLink",function(){return d})},function(e,t,r){"use strict";r.r(t);var n=r(0),i=r(14),o=r(6),a=r(25),u=r(13),c={test:function(e){return"client"===e.name.value},remove:!0},s=new Map;r.d(t,"withClientState",function(){return f});var l=function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),f=function(e){void 0===e&&(e={resolvers:{},defaults:{}});var t=e.resolvers,r=e.defaults,f=e.cache,d=e.typeDefs;return f&&r&&f.writeData({data:r}),new(function(e){function p(){return null!==e&&e.apply(this,arguments)||this}return l(p,e),p.prototype.writeDefaults=function(){f&&r&&f.writeData({data:r})},p.prototype.request=function(e,l){if(void 0===l&&(l=function(){return n.Observable.of({data:{}})}),d){var f="string"==typeof d?d:d.map(function(e){return e.trim()}).join("\n");e.setContext(function(e){var t=e.schemas;return{schemas:(void 0===t?[]:t).concat([{definition:f,directives:"directive @client on FIELD"}])}})}if(!Object(i.d)(["client"],e.query))return l(e);var p=function(e){var t=s.get(e);if(t)return t;Object(o.a)(e);var r=Object(u.d)([c],e);return s.set(e,r),r}(e.query),h=e.query,v=function(e){return e.charAt(0).toUpperCase()+e.slice(1)}((Object(o.f)(h)||{}).operation)||"Query",y=function(e,n,i,o,a){void 0===n&&(n={});var u=n[a.resultKey];if(void 0!==u)return u;var c=t[n.__typename||v];if(c){var s=c[e];if(s)return s(n,i,o,a)}return r[e]};return new n.Observable(function(t){p&&(e.query=p);var r=p&&l?l(e):n.Observable.of({data:{}}),i=t.error.bind(t),o=r.subscribe({next:function(r){var n=r.data,o=r.errors,u=e.getContext();Object(a.graphql)(y,h,n,u,e.variables).then(function(e){t.next({data:e,errors:o}),t.complete()}).catch(i)},error:i});return function(){o&&o.unsubscribe()}})},p}(n.ApolloLink))}}]); -------------------------------------------------------------------------------- /app/public/js/index.js: -------------------------------------------------------------------------------- 1 | import ApolloClient from 'apollo-boost'; 2 | import gql from 'graphql-tag'; 3 | 4 | const client = new ApolloClient(); 5 | const query = gql` 6 | query { 7 | posts { 8 | title 9 | author { 10 | firstName 11 | } 12 | } 13 | } 14 | `; 15 | 16 | const body = document.body; 17 | client.query({ query }).then((results) => { 18 | results.data.posts.forEach( (post) => renderPost(body, post) ); 19 | }); 20 | 21 | const renderPost = (body, post) => { 22 | const section = document.createElement('section'); 23 | const domString = ` 24 |

25 | Post: ${post.title} 26 |

27 |

28 | Author: ${post.author.firstName} 29 |

30 | `; 31 | section.innerHTML = domString; 32 | body.appendChild(section); 33 | }; -------------------------------------------------------------------------------- /config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "development": { 3 | "username": "root", 4 | "password": null, 5 | "database": "api_node_demo", 6 | "host": "127.0.0.1", 7 | "dialect": "mysql" 8 | }, 9 | "test": { 10 | "username": "root", 11 | "password": null, 12 | "database": "database_test", 13 | "host": "127.0.0.1", 14 | "dialect": "mysql" 15 | }, 16 | "production": { 17 | "username": "root", 18 | "password": null, 19 | "database": "database_production", 20 | "host": "127.0.0.1", 21 | "dialect": "mysql" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /graphql-playground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sakai-san/graphqlApiNodeDemo/a3373bff7f51df9402cfb3d91a3e0461ef9abf9f/graphql-playground.png -------------------------------------------------------------------------------- /models/author.js: -------------------------------------------------------------------------------- 1 | export default (sequelize, DataTypes) => { 2 | const Author = sequelize.define('author', { 3 | id: { 4 | type: DataTypes.INTEGER, 5 | primaryKey: true, 6 | autoIncrement: true, 7 | }, 8 | firstName: DataTypes.STRING, 9 | lastName: DataTypes.STRING, 10 | }, 11 | { 12 | freezeTableName: true, 13 | }); 14 | 15 | Author.associate = (models) => { 16 | Author.hasMany(models.post); 17 | }; 18 | 19 | return Author; 20 | }; 21 | -------------------------------------------------------------------------------- /models/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var Sequelize = require('sequelize'); 6 | var basename = path.basename(__filename); 7 | var env = process.env.NODE_ENV || 'development'; 8 | var config = require(__dirname + '/../config/config.json')[env]; 9 | var db = {}; 10 | 11 | if (config.use_env_variable) { 12 | var sequelize = new Sequelize(process.env[config.use_env_variable], config); 13 | } else { 14 | var sequelize = new Sequelize(config.database, config.username, config.password, config); 15 | } 16 | 17 | fs 18 | .readdirSync(__dirname) 19 | .filter(file => { 20 | return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); 21 | }) 22 | .forEach(file => { 23 | var model = sequelize['import'](path.join(__dirname, file)); 24 | db[model.name] = model; 25 | }); 26 | 27 | Object.keys(db).forEach(modelName => { 28 | if (db[modelName].associate) { 29 | db[modelName].associate(db); 30 | } 31 | }); 32 | 33 | db.sequelize = sequelize; 34 | db.Sequelize = Sequelize; 35 | 36 | module.exports = db; 37 | -------------------------------------------------------------------------------- /models/post.js: -------------------------------------------------------------------------------- 1 | export default (sequelize, DataTypes) => { 2 | const Post = sequelize.define('post', { 3 | id: { 4 | type: DataTypes.INTEGER, 5 | primaryKey: true, 6 | autoIncrement: true, 7 | }, 8 | title: DataTypes.STRING, 9 | content: { 10 | type: DataTypes.TEXT, 11 | allowNull: false, 12 | }, 13 | }, 14 | { 15 | freezeTableName: true, 16 | }); 17 | 18 | Post.associate = (models) => { 19 | Post.belongsTo(models.author); 20 | }; 21 | 22 | return Post; 23 | }; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graphqlApiNodeDemo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "build": "webpack --entry ./app/public/js/index.js --output-filename bundle.min.js --output-path ./app/public/js ", 7 | "start": "npm run init-db && npx nodemon --exec babel-node server.js", 8 | "sequelize-skeleton": "npx sequelize init:models; npx sequelize init:config", 9 | "init-db": "cd /opt/lampp/bin/ && echo 'DROP DATABASE IF EXISTS api_node_demo; CREATE DATABASE api_node_demo CHARACTER SET utf8 COLLATE utf8_general_ci' | ./mysql -u root && cd -", 10 | "dockerize-db": "docker run -p 3306:3306 --name toma-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true -d mysql", 11 | "init-dockerize-db": "docker exec -i toma-mysql mysql -uroot <<< 'DROP DATABASE IF EXISTS api_node_demo; CREATE DATABASE api_node_demo CHARACTER SET utf8 COLLATE utf8_general_ci'", 12 | "start-dockerize-db": "npx nodemon --exec babel-node server.js", 13 | "check-docker-logs": "docker logs toma-mysql" 14 | }, 15 | "dependencies": { 16 | "apollo-boost": "^0.1.13", 17 | "apollo-server-express": "^2.0.0", 18 | "body-parser": "^1.18.3", 19 | "express": "^4.16.3", 20 | "graphql": "^0.13.2", 21 | "graphql-tag": "^2.9.2", 22 | "mysql2": "^2.0.0", 23 | "sequelize": "^5.9.4" 24 | }, 25 | "private": true, 26 | "keywords": [], 27 | "author": "Infocentric Research AG, Baden, Switzerland", 28 | "license": "ISC", 29 | "devDependencies": { 30 | "babel-cli": "^6.26.0", 31 | "babel-preset-env": "^1.7.0", 32 | "babel-preset-stage-3": "^6.24.1", 33 | "faker": "^4.1.0", 34 | "lodash.random": "^3.2.0", 35 | "lodash.times": "^4.3.2", 36 | "nodemon": "^1.18.3", 37 | "sequelize-cli": "^4.0.0", 38 | "webpack": "^4.16.5", 39 | "webpack-cli": "^3.1.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /resolvers.js: -------------------------------------------------------------------------------- 1 | export default { 2 | Author: { 3 | posts: (parent, args, context, info) => parent.getPosts() 4 | }, 5 | Post: { 6 | author: (parent, args, context, info) => parent.getAuthor() 7 | }, 8 | Query: { 9 | posts: (parent, args, { db }, info) => db.post.findAll(), 10 | authors: (parent, args, { db }, info) => db.author.findAll(), 11 | post: (parent, { id }, { db }, info) => db.post.findByPk(id), 12 | author: (parent, { id }, { db }, info) => db.author.findByPk(id) 13 | }, 14 | Mutation: { 15 | createPost: (parent, { title, content, authorId }, { db }, info) => 16 | db.post.create({ 17 | title: title, 18 | content: content, 19 | authorId: authorId 20 | }), 21 | updatePost: (parent, { title, content, id }, { db }, info) => 22 | db.post.update( 23 | { 24 | title: title, 25 | content: content 26 | }, 27 | { 28 | where: { 29 | id: id 30 | } 31 | } 32 | ), 33 | deletePost: (parent, { id }, { db }, info) => 34 | db.post.destroy({ 35 | where: { 36 | id: id 37 | } 38 | }) 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /schema.js: -------------------------------------------------------------------------------- 1 | export default ` 2 | type Author { 3 | id: ID! 4 | firstName: String! 5 | lastName: String! 6 | posts: [Post!]! 7 | } 8 | 9 | type Post { 10 | id: ID! 11 | title: String 12 | content: String! 13 | authorId: ID! 14 | author: Author! 15 | } 16 | 17 | type Query { 18 | posts: [Post!]! 19 | post(id: ID!): Post 20 | author(id: ID!): Author 21 | authors: [Author!]! 22 | } 23 | 24 | type Mutation { 25 | createPost(title: String, content:String!, authorId: ID!): Post! 26 | updatePost(id: ID!, title: String, content:String!): [Int!]! 27 | deletePost(id: ID!): Int! 28 | } 29 | `; -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import { ApolloServer, gql } from "apollo-server-express"; 3 | import faker from "faker"; 4 | import times from "lodash.times"; 5 | import random from "lodash.random"; 6 | import typeDefs from "./schema"; 7 | import resolvers from "./resolvers"; 8 | import db from "./models"; 9 | 10 | const playground = { 11 | settings: { 12 | "editor.cursorShape": "line" 13 | } 14 | }; 15 | 16 | const server = new ApolloServer({ 17 | typeDefs: gql(typeDefs), 18 | resolvers, 19 | context: { db }, 20 | playground 21 | }); 22 | 23 | const app = express(); 24 | server.applyMiddleware({ app }); 25 | 26 | app.use(express.static("app/public")); 27 | 28 | db.sequelize.sync().then(() => { 29 | // populate author table with dummy data 30 | db.author.bulkCreate( 31 | times(10, () => ({ 32 | firstName: faker.name.firstName(), 33 | lastName: faker.name.lastName() 34 | })) 35 | ); 36 | // populate post table with dummy data 37 | db.post.bulkCreate( 38 | times(10, () => ({ 39 | title: faker.lorem.sentence(), 40 | content: faker.lorem.paragraph(), 41 | authorId: random(1, 10) 42 | })) 43 | ); 44 | 45 | app.listen({ port: 4000 }, () => 46 | console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`) 47 | ); 48 | }); 49 | --------------------------------------------------------------------------------