graphiql-rails 1.8.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +1,88 @@
1
- document.addEventListener("DOMContentLoaded", function(event) {
2
- var graphiqlContainer = document.getElementById("graphiql-container");
3
- var parameters = {};
1
+ document.addEventListener("DOMContentLoaded", function (_) {
2
+ const graphiqlContainer = document.getElementById("graphiql-container");
4
3
 
5
- var queryParams = graphiqlContainer.dataset.queryParams;
4
+ // Defines a GraphQL fetcher using the fetch API.
5
+ function graphQLFetcher(graphQLParams, options) {
6
+ const graphQLEndpoint = graphiqlContainer.dataset.graphqlEndpointPath;
7
+ const providedHeaders = JSON.parse(graphiqlContainer.dataset.headers);
6
8
 
7
- function onEditQuery(newQuery) {
8
- parameters.query = newQuery;
9
- updateURL();
10
- }
11
- function onEditVariables(newVariables) {
12
- parameters.variables = newVariables;
13
- updateURL();
14
- }
15
- function updateURL() {
16
- var newSearch = '?' + Object.keys(parameters).map(function (key) {
17
- return encodeURIComponent(key) + '=' +
18
- encodeURIComponent(parameters[key]);
19
- }).join('&');
20
- history.replaceState(null, null, newSearch);
21
- }
22
-
23
- if (queryParams === 'true') {
24
- // Parse the search string to get url parameters.
25
- var search = window.location.search;
26
- search.substr(1).split('&').forEach(function (entry) {
27
- var eq = entry.indexOf('=');
28
- if (eq >= 0) {
29
- parameters[decodeURIComponent(entry.slice(0, eq))] =
30
- decodeURIComponent(entry.slice(eq + 1));
31
- }
32
- });
33
- // if variables was provided, try to format it.
34
- if (parameters.variables) {
35
- try {
36
- parameters.variables =
37
- JSON.stringify(JSON.parse(parameters.variables), null, 2);
38
- } catch (e) {
39
- // Do nothing, we want to display the invalid JSON as a string, rather
40
- // than present an error.
41
- }
9
+ return fetch(graphQLEndpoint, {
10
+ method: 'post',
11
+ headers: {...providedHeaders, ...options.headers},
12
+ body: JSON.stringify(graphQLParams),
13
+ credentials: 'include',
14
+ }).then(function (response) {
15
+ try {
16
+ return response.json();
17
+ } catch (error) {
18
+ return {
19
+ "status": response.status,
20
+ "message": "The server responded with invalid JSON, this is probably a server-side error",
21
+ "response": response.text(),
22
+ };
23
+ }
24
+ })
42
25
  }
43
- // When the query and variables string is edited, update the URL bar so
44
- // that it can be easily shared
45
- }
46
26
 
27
+ // Render <GraphiQL /> into the body.
28
+ const initialQuery = graphiqlContainer.dataset.initialQuery;
29
+ let elementProps = {
30
+ fetcher: graphQLFetcher,
31
+ defaultQuery: initialQuery ? initialQuery : undefined,
32
+ headerEditorEnabled: graphiqlContainer.dataset.headerEditorEnabled === 'true',
33
+ inputValueDeprecation: graphiqlContainer.dataset.inputValueDeprecation === 'true',
34
+ };
35
+
36
+ if (graphiqlContainer.dataset.queryParams === 'true') {
37
+ let parameters = {};
47
38
 
48
- // Defines a GraphQL fetcher using the fetch API.
49
- var graphQLEndpoint = graphiqlContainer.dataset.graphqlEndpointPath;
50
- function graphQLFetcher(graphQLParams) {
51
- return fetch(graphQLEndpoint, {
52
- method: 'post',
53
- headers: JSON.parse(graphiqlContainer.dataset.headers),
54
- body: JSON.stringify(graphQLParams),
55
- credentials: 'include',
56
- }).then(function(response) {
57
- try {
58
- return response.json();
59
- } catch(error) {
60
- return {
61
- "status": response.status,
62
- "message": "The server responded with invalid JSON, this is probably a server-side error",
63
- "response": response.text(),
64
- };
65
- }
66
- })
67
- }
39
+ // Parse the search string to get url parameters
40
+ window.location.search.substring(1).split('&').forEach(function (entry) {
41
+ let eq = entry.indexOf('=');
42
+ if (eq >= 0) {
43
+ parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(entry.slice(eq + 1));
44
+ }
45
+ });
68
46
 
69
- var initial_query = graphiqlContainer.dataset.initialQuery;
47
+ // If variables was provided, try to format it
48
+ if (parameters.variables) {
49
+ try {
50
+ parameters.variables = JSON.stringify(JSON.parse(parameters.variables), null, 2);
51
+ } catch {
52
+ // Do nothing, we want to display the invalid JSON as a string, rather than present an error
53
+ }
54
+ }
70
55
 
71
- if (initial_query) {
72
- var defaultQuery = initial_query;
73
- } else {
74
- var defaultQuery = undefined;
75
- }
56
+ // When the query and variables string is edited, update the URL bar so that it can be easily shared
57
+ function updateURL() {
58
+ const newSearch = '?' + Object.keys(parameters).map(function (key) {
59
+ return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]);
60
+ }).join('&');
61
+ history.replaceState(null, null, newSearch);
62
+ }
76
63
 
64
+ function onEditQuery(newQuery) {
65
+ parameters.query = newQuery;
66
+ updateURL();
67
+ }
77
68
 
78
- // Render <GraphiQL /> into the body.
79
- var elementProps = { fetcher: graphQLFetcher, defaultQuery: defaultQuery, };
80
-
81
- Object.assign(elementProps, { query: parameters.query, variables: parameters.variables })
82
- if (queryParams === 'true') {
83
- Object.assign(elementProps, { onEditQuery: onEditQuery, onEditVariables: onEditVariables });
84
- }
69
+ function onEditVariables(newVariables) {
70
+ parameters.variables = newVariables;
71
+ updateURL();
72
+ }
73
+
74
+ Object.assign(elementProps, {
75
+ query: parameters.query,
76
+ variables: parameters.variables,
77
+ onEditQuery: onEditQuery,
78
+ onEditVariables: onEditVariables
79
+ })
80
+ }
85
81
 
86
- ReactDOM.render(
87
- React.createElement(GraphiQL, elementProps,
88
- React.createElement(GraphiQL.Logo, {}, graphiqlContainer.dataset.logo)
89
- ),
90
- document.getElementById("graphiql-container")
91
- );
92
- });
82
+ ReactDOM.render(
83
+ React.createElement(GraphiQL, elementProps,
84
+ React.createElement(GraphiQL.Logo, {}, graphiqlContainer.dataset.logo)
85
+ ),
86
+ document.getElementById("graphiql-container")
87
+ );
88
+ });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license React
3
+ * react.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ (function(){'use strict';(function(c,x){"object"===typeof exports&&"undefined"!==typeof module?x(exports):"function"===typeof define&&define.amd?define(["exports"],x):(c=c||self,x(c.React={}))})(this,function(c){function x(a){if(null===a||"object"!==typeof a)return null;a=V&&a[V]||a["@@iterator"];return"function"===typeof a?a:null}function w(a,b,e){this.props=a;this.context=b;this.refs=W;this.updater=e||X}function Y(){}function K(a,b,e){this.props=a;this.context=b;this.refs=W;this.updater=e||X}function Z(a,b,
11
+ e){var m,d={},c=null,h=null;if(null!=b)for(m in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(c=""+b.key),b)aa.call(b,m)&&!ba.hasOwnProperty(m)&&(d[m]=b[m]);var l=arguments.length-2;if(1===l)d.children=e;else if(1<l){for(var f=Array(l),k=0;k<l;k++)f[k]=arguments[k+2];d.children=f}if(a&&a.defaultProps)for(m in l=a.defaultProps,l)void 0===d[m]&&(d[m]=l[m]);return{$$typeof:y,type:a,key:c,ref:h,props:d,_owner:L.current}}function na(a,b){return{$$typeof:y,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}
12
+ function M(a){return"object"===typeof a&&null!==a&&a.$$typeof===y}function oa(a){var b={"=":"=0",":":"=2"};return"$"+a.replace(/[=:]/g,function(a){return b[a]})}function N(a,b){return"object"===typeof a&&null!==a&&null!=a.key?oa(""+a.key):b.toString(36)}function B(a,b,e,m,d){var c=typeof a;if("undefined"===c||"boolean"===c)a=null;var h=!1;if(null===a)h=!0;else switch(c){case "string":case "number":h=!0;break;case "object":switch(a.$$typeof){case y:case pa:h=!0}}if(h)return h=a,d=d(h),a=""===m?"."+
13
+ N(h,0):m,ca(d)?(e="",null!=a&&(e=a.replace(da,"$&/")+"/"),B(d,b,e,"",function(a){return a})):null!=d&&(M(d)&&(d=na(d,e+(!d.key||h&&h.key===d.key?"":(""+d.key).replace(da,"$&/")+"/")+a)),b.push(d)),1;h=0;m=""===m?".":m+":";if(ca(a))for(var l=0;l<a.length;l++){c=a[l];var f=m+N(c,l);h+=B(c,b,e,f,d)}else if(f=x(a),"function"===typeof f)for(a=f.call(a),l=0;!(c=a.next()).done;)c=c.value,f=m+N(c,l++),h+=B(c,b,e,f,d);else if("object"===c)throw b=String(a),Error("Objects are not valid as a React child (found: "+
14
+ ("[object Object]"===b?"object with keys {"+Object.keys(a).join(", ")+"}":b)+"). If you meant to render a collection of children, use an array instead.");return h}function C(a,b,e){if(null==a)return a;var c=[],d=0;B(a,c,"","",function(a){return b.call(e,a,d++)});return c}function qa(a){if(-1===a._status){var b=a._result;b=b();b.then(function(b){if(0===a._status||-1===a._status)a._status=1,a._result=b},function(b){if(0===a._status||-1===a._status)a._status=2,a._result=b});-1===a._status&&(a._status=
15
+ 0,a._result=b)}if(1===a._status)return a._result.default;throw a._result;}function O(a,b){var e=a.length;a.push(b);a:for(;0<e;){var c=e-1>>>1,d=a[c];if(0<D(d,b))a[c]=b,a[e]=d,e=c;else break a}}function p(a){return 0===a.length?null:a[0]}function E(a){if(0===a.length)return null;var b=a[0],e=a.pop();if(e!==b){a[0]=e;a:for(var c=0,d=a.length,k=d>>>1;c<k;){var h=2*(c+1)-1,l=a[h],f=h+1,g=a[f];if(0>D(l,e))f<d&&0>D(g,l)?(a[c]=g,a[f]=e,c=f):(a[c]=l,a[h]=e,c=h);else if(f<d&&0>D(g,e))a[c]=g,a[f]=e,c=f;else break a}}return b}
16
+ function D(a,b){var c=a.sortIndex-b.sortIndex;return 0!==c?c:a.id-b.id}function P(a){for(var b=p(r);null!==b;){if(null===b.callback)E(r);else if(b.startTime<=a)E(r),b.sortIndex=b.expirationTime,O(q,b);else break;b=p(r)}}function Q(a){z=!1;P(a);if(!u)if(null!==p(q))u=!0,R(S);else{var b=p(r);null!==b&&T(Q,b.startTime-a)}}function S(a,b){u=!1;z&&(z=!1,ea(A),A=-1);F=!0;var c=k;try{P(b);for(n=p(q);null!==n&&(!(n.expirationTime>b)||a&&!fa());){var m=n.callback;if("function"===typeof m){n.callback=null;
17
+ k=n.priorityLevel;var d=m(n.expirationTime<=b);b=v();"function"===typeof d?n.callback=d:n===p(q)&&E(q);P(b)}else E(q);n=p(q)}if(null!==n)var g=!0;else{var h=p(r);null!==h&&T(Q,h.startTime-b);g=!1}return g}finally{n=null,k=c,F=!1}}function fa(){return v()-ha<ia?!1:!0}function R(a){G=a;H||(H=!0,I())}function T(a,b){A=ja(function(){a(v())},b)}var y=Symbol.for("react.element"),pa=Symbol.for("react.portal"),ra=Symbol.for("react.fragment"),sa=Symbol.for("react.strict_mode"),ta=Symbol.for("react.profiler"),
18
+ ua=Symbol.for("react.provider"),va=Symbol.for("react.context"),wa=Symbol.for("react.forward_ref"),xa=Symbol.for("react.suspense"),ya=Symbol.for("react.memo"),za=Symbol.for("react.lazy"),V=Symbol.iterator,X={isMounted:function(a){return!1},enqueueForceUpdate:function(a,b,c){},enqueueReplaceState:function(a,b,c,m){},enqueueSetState:function(a,b,c,m){}},ka=Object.assign,W={};w.prototype.isReactComponent={};w.prototype.setState=function(a,b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
19
+ this.updater.enqueueSetState(this,a,b,"setState")};w.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate")};Y.prototype=w.prototype;var t=K.prototype=new Y;t.constructor=K;ka(t,w.prototype);t.isPureReactComponent=!0;var ca=Array.isArray,aa=Object.prototype.hasOwnProperty,L={current:null},ba={key:!0,ref:!0,__self:!0,__source:!0},da=/\/+/g,g={current:null},J={transition:null};if("object"===typeof performance&&"function"===typeof performance.now){var Aa=performance;
20
+ var v=function(){return Aa.now()}}else{var la=Date,Ba=la.now();v=function(){return la.now()-Ba}}var q=[],r=[],Ca=1,n=null,k=3,F=!1,u=!1,z=!1,ja="function"===typeof setTimeout?setTimeout:null,ea="function"===typeof clearTimeout?clearTimeout:null,ma="undefined"!==typeof setImmediate?setImmediate:null;"undefined"!==typeof navigator&&void 0!==navigator.scheduling&&void 0!==navigator.scheduling.isInputPending&&navigator.scheduling.isInputPending.bind(navigator.scheduling);var H=!1,G=null,A=-1,ia=5,ha=
21
+ -1,U=function(){if(null!==G){var a=v();ha=a;var b=!0;try{b=G(!0,a)}finally{b?I():(H=!1,G=null)}}else H=!1};if("function"===typeof ma)var I=function(){ma(U)};else if("undefined"!==typeof MessageChannel){t=new MessageChannel;var Da=t.port2;t.port1.onmessage=U;I=function(){Da.postMessage(null)}}else I=function(){ja(U,0)};t={ReactCurrentDispatcher:g,ReactCurrentOwner:L,ReactCurrentBatchConfig:J,Scheduler:{__proto__:null,unstable_ImmediatePriority:1,unstable_UserBlockingPriority:2,unstable_NormalPriority:3,
22
+ unstable_IdlePriority:5,unstable_LowPriority:4,unstable_runWithPriority:function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=k;k=a;try{return b()}finally{k=c}},unstable_next:function(a){switch(k){case 1:case 2:case 3:var b=3;break;default:b=k}var c=k;k=b;try{return a()}finally{k=c}},unstable_scheduleCallback:function(a,b,c){var e=v();"object"===typeof c&&null!==c?(c=c.delay,c="number"===typeof c&&0<c?e+c:e):c=e;switch(a){case 1:var d=-1;break;case 2:d=250;break;case 5:d=
23
+ 1073741823;break;case 4:d=1E4;break;default:d=5E3}d=c+d;a={id:Ca++,callback:b,priorityLevel:a,startTime:c,expirationTime:d,sortIndex:-1};c>e?(a.sortIndex=c,O(r,a),null===p(q)&&a===p(r)&&(z?(ea(A),A=-1):z=!0,T(Q,c-e))):(a.sortIndex=d,O(q,a),u||F||(u=!0,R(S)));return a},unstable_cancelCallback:function(a){a.callback=null},unstable_wrapCallback:function(a){var b=k;return function(){var c=k;k=b;try{return a.apply(this,arguments)}finally{k=c}}},unstable_getCurrentPriorityLevel:function(){return k},unstable_shouldYield:fa,
24
+ unstable_requestPaint:function(){},unstable_continueExecution:function(){u||F||(u=!0,R(S))},unstable_pauseExecution:function(){},unstable_getFirstCallbackNode:function(){return p(q)},get unstable_now(){return v},unstable_forceFrameRate:function(a){0>a||125<a?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):ia=0<a?Math.floor(1E3/a):5},unstable_Profiling:null}};c.Children={map:C,forEach:function(a,b,c){C(a,function(){b.apply(this,
25
+ arguments)},c)},count:function(a){var b=0;C(a,function(){b++});return b},toArray:function(a){return C(a,function(a){return a})||[]},only:function(a){if(!M(a))throw Error("React.Children.only expected to receive a single React element child.");return a}};c.Component=w;c.Fragment=ra;c.Profiler=ta;c.PureComponent=K;c.StrictMode=sa;c.Suspense=xa;c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=t;c.cloneElement=function(a,b,c){if(null===a||void 0===a)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+
26
+ a+".");var e=ka({},a.props),d=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=L.current);void 0!==b.key&&(d=""+b.key);if(a.type&&a.type.defaultProps)var l=a.type.defaultProps;for(f in b)aa.call(b,f)&&!ba.hasOwnProperty(f)&&(e[f]=void 0===b[f]&&void 0!==l?l[f]:b[f])}var f=arguments.length-2;if(1===f)e.children=c;else if(1<f){l=Array(f);for(var g=0;g<f;g++)l[g]=arguments[g+2];e.children=l}return{$$typeof:y,type:a.type,key:d,ref:k,props:e,_owner:h}};c.createContext=function(a){a={$$typeof:va,
27
+ _currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};a.Provider={$$typeof:ua,_context:a};return a.Consumer=a};c.createElement=Z;c.createFactory=function(a){var b=Z.bind(null,a);b.type=a;return b};c.createRef=function(){return{current:null}};c.forwardRef=function(a){return{$$typeof:wa,render:a}};c.isValidElement=M;c.lazy=function(a){return{$$typeof:za,_payload:{_status:-1,_result:a},_init:qa}};c.memo=function(a,b){return{$$typeof:ya,type:a,
28
+ compare:void 0===b?null:b}};c.startTransition=function(a,b){b=J.transition;J.transition={};try{a()}finally{J.transition=b}};c.unstable_act=function(a){throw Error("act(...) is not supported in production builds of React.");};c.useCallback=function(a,b){return g.current.useCallback(a,b)};c.useContext=function(a){return g.current.useContext(a)};c.useDebugValue=function(a,b){};c.useDeferredValue=function(a){return g.current.useDeferredValue(a)};c.useEffect=function(a,b){return g.current.useEffect(a,
29
+ b)};c.useId=function(){return g.current.useId()};c.useImperativeHandle=function(a,b,c){return g.current.useImperativeHandle(a,b,c)};c.useInsertionEffect=function(a,b){return g.current.useInsertionEffect(a,b)};c.useLayoutEffect=function(a,b){return g.current.useLayoutEffect(a,b)};c.useMemo=function(a,b){return g.current.useMemo(a,b)};c.useReducer=function(a,b,c){return g.current.useReducer(a,b,c)};c.useRef=function(a){return g.current.useRef(a)};c.useState=function(a){return g.current.useState(a)};
30
+ c.useSyncExternalStore=function(a,b,c){return g.current.useSyncExternalStore(a,b,c)};c.useTransition=function(){return g.current.useTransition()};c.version="18.2.0"});
31
+ })();