@webiny/handler-graphql 0.0.0-mt-3 → 0.0.0-unstable.8c4d9f045a

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.
Files changed (39) hide show
  1. package/builtInTypes/AnyScalar.js.map +1 -0
  2. package/builtInTypes/DateScalar.js +4 -4
  3. package/builtInTypes/DateScalar.js.map +1 -0
  4. package/builtInTypes/DateTimeScalar.js +2 -2
  5. package/builtInTypes/DateTimeScalar.js.map +1 -0
  6. package/builtInTypes/DateTimeZScalar.js.map +1 -0
  7. package/builtInTypes/JsonScalar.js.map +1 -0
  8. package/builtInTypes/LongScalar.js.map +1 -0
  9. package/builtInTypes/NumberScalar.js.map +1 -0
  10. package/builtInTypes/RefInputScalar.js.map +1 -0
  11. package/builtInTypes/TimeScalar.js.map +1 -0
  12. package/builtInTypes/index.js.map +1 -0
  13. package/createGraphQLHandler.js +29 -46
  14. package/createGraphQLHandler.js.map +1 -0
  15. package/createGraphQLSchema.d.ts +2 -3
  16. package/createGraphQLSchema.js +10 -3
  17. package/createGraphQLSchema.js.map +1 -0
  18. package/debugPlugins.d.ts +10 -8
  19. package/debugPlugins.js +17 -20
  20. package/debugPlugins.js.map +1 -0
  21. package/errors.d.ts +2 -2
  22. package/errors.js.map +1 -0
  23. package/index.d.ts +10 -3
  24. package/index.js.map +1 -0
  25. package/interceptConsole.d.ts +5 -1
  26. package/interceptConsole.js +6 -2
  27. package/interceptConsole.js.map +1 -0
  28. package/package.json +18 -18
  29. package/plugins/GraphQLSchemaPlugin.d.ts +2 -2
  30. package/plugins/GraphQLSchemaPlugin.js.map +1 -0
  31. package/plugins/index.js.map +1 -0
  32. package/processRequestBody.d.ts +4 -1
  33. package/processRequestBody.js +5 -7
  34. package/processRequestBody.js.map +1 -0
  35. package/responses.d.ts +20 -18
  36. package/responses.js +23 -4
  37. package/responses.js.map +1 -0
  38. package/types.d.ts +7 -5
  39. package/types.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["returnValue","value","Any","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["AnyScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst returnValue = (value: any): any => {\n return value;\n};\n\nexport const Any = new GraphQLScalarType({\n name: \"Any\",\n description: `A scalar type that represents an ambiguous value.`,\n serialize: returnValue,\n parseValue: returnValue\n});\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,WAAW,GAAIC,KAAD,IAAqB;EACrC,OAAOA,KAAP;AACH,CAFD;;AAIO,MAAMC,GAAG,GAAG,IAAIC,0BAAJ,CAAsB;EACrCC,IAAI,EAAE,KAD+B;EAErCC,WAAW,EAAG,mDAFuB;EAGrCC,SAAS,EAAEN,WAH0B;EAIrCO,UAAU,EAAEP;AAJyB,CAAtB,CAAZ"}
@@ -13,9 +13,9 @@ var _graphqlScalars = require("graphql-scalars");
13
13
 
14
14
  var _graphql = require("graphql");
15
15
 
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
17
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
19
 
20
20
  const DateScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateResolver), {}, {
21
21
  serialize: value => {
@@ -25,10 +25,10 @@ const DateScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}
25
25
 
26
26
  try {
27
27
  const date = new Date(value);
28
- return date.toISOString().substr(0, 10);
28
+ return date.toISOString().slice(0, 10);
29
29
  } catch (ex) {
30
30
  if (value.toISOString) {
31
- return value.toISOString().substr(0, 10);
31
+ return value.toISOString().slice(0, 10);
32
32
  }
33
33
 
34
34
  throw ex;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DateScalar","GraphQLScalarType","DateResolver","serialize","value","date","Date","toISOString","slice","ex"],"sources":["DateScalar.ts"],"sourcesContent":["import { DateResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nexport const DateScalar = new GraphQLScalarType({\n ...DateResolver,\n serialize: value => {\n if (!value) {\n return null;\n }\n try {\n const date = new Date(value);\n return date.toISOString().slice(0, 10);\n } catch (ex) {\n if (value.toISOString) {\n return value.toISOString().slice(0, 10);\n }\n throw ex;\n }\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;;;;;AACO,MAAMA,UAAU,GAAG,IAAIC,0BAAJ,iCACnBC,4BADmB;EAEtBC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAL,EAAY;MACR,OAAO,IAAP;IACH;;IACD,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAJ,CAASF,KAAT,CAAb;MACA,OAAOC,IAAI,CAACE,WAAL,GAAmBC,KAAnB,CAAyB,CAAzB,EAA4B,EAA5B,CAAP;IACH,CAHD,CAGE,OAAOC,EAAP,EAAW;MACT,IAAIL,KAAK,CAACG,WAAV,EAAuB;QACnB,OAAOH,KAAK,CAACG,WAAN,GAAoBC,KAApB,CAA0B,CAA1B,EAA6B,EAA7B,CAAP;MACH;;MACD,MAAMC,EAAN;IACH;EACJ;AAfqB,GAAnB"}
@@ -13,9 +13,9 @@ var _graphqlScalars = require("graphql-scalars");
13
13
 
14
14
  var _graphql = require("graphql");
15
15
 
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
17
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
19
 
20
20
  const DateTimeScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateTimeResolver), {}, {
21
21
  serialize: value => {
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DateTimeScalar","GraphQLScalarType","DateTimeResolver","serialize","value","date","Date","toISOString","ex"],"sources":["DateTimeScalar.ts"],"sourcesContent":["import { DateTimeResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nexport const DateTimeScalar = new GraphQLScalarType({\n ...DateTimeResolver,\n serialize: value => {\n if (!value) {\n return null;\n }\n try {\n const date = new Date(value);\n return date.toISOString();\n } catch (ex) {\n if (value.toISOString) {\n return value.toISOString();\n }\n throw ex;\n }\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;;;;;AACO,MAAMA,cAAc,GAAG,IAAIC,0BAAJ,iCACvBC,gCADuB;EAE1BC,SAAS,EAAEC,KAAK,IAAI;IAChB,IAAI,CAACA,KAAL,EAAY;MACR,OAAO,IAAP;IACH;;IACD,IAAI;MACA,MAAMC,IAAI,GAAG,IAAIC,IAAJ,CAASF,KAAT,CAAb;MACA,OAAOC,IAAI,CAACE,WAAL,EAAP;IACH,CAHD,CAGE,OAAOC,EAAP,EAAW;MACT,IAAIJ,KAAK,CAACG,WAAV,EAAuB;QACnB,OAAOH,KAAK,CAACG,WAAN,EAAP;MACH;;MACD,MAAMC,EAAN;IACH;EACJ;AAfyB,GAAvB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateTimeZone","value","timeWithTimezone","split","WebinyError","separator","includes","zone","hoursMinutes","hours","minutes","undefined","length","DateTimeZScalar","GraphQLScalarType","name","description","parseValue","DateTimeResolver","serialize"],"sources":["DateTimeZScalar.ts"],"sourcesContent":["import { DateTimeResolver } from \"graphql-scalars\";\nimport { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst validateTimeZone = (value: string): void => {\n const timeWithTimezone = value.split(\"T\")[1];\n if (!timeWithTimezone) {\n throw new WebinyError(\n \"Could not extract time with timezone from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value\n }\n );\n }\n const separator = timeWithTimezone.includes(\"-\") ? \"-\" : \"+\";\n const zone = timeWithTimezone.split(separator)[1];\n if (!zone) {\n throw new WebinyError(\n \"Could not extract timezone from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value: timeWithTimezone\n }\n );\n }\n const hoursMinutes = zone.split(\":\");\n const [hours, minutes] = hoursMinutes;\n if (hours === undefined || minutes === undefined || hoursMinutes.length !== 2) {\n throw new WebinyError(\n \"Could not extract hours or minutes from value.\",\n \"DATE_TIME_TIMEZONE_ERROR\",\n {\n value: zone\n }\n );\n }\n};\n/**\n * A custom type for dateTime with the timezone.\n * Must be in format \"YYYY-MM-ddTHH:mm:ss+HH:mm\".\n */\nexport const DateTimeZScalar = new GraphQLScalarType({\n name: \"DateTimeZ\",\n description: \"A custom type for dateTime with the timezone.\",\n parseValue: value => {\n // this serves as validator\n DateTimeResolver.parseValue(value);\n validateTimeZone(value);\n return value;\n },\n serialize: value => {\n return value;\n }\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,gBAAgB,GAAIC,KAAD,IAAyB;EAC9C,MAAMC,gBAAgB,GAAGD,KAAK,CAACE,KAAN,CAAY,GAAZ,EAAiB,CAAjB,CAAzB;;EACA,IAAI,CAACD,gBAAL,EAAuB;IACnB,MAAM,IAAIE,cAAJ,CACF,kDADE,EAEF,0BAFE,EAGF;MACIH;IADJ,CAHE,CAAN;EAOH;;EACD,MAAMI,SAAS,GAAGH,gBAAgB,CAACI,QAAjB,CAA0B,GAA1B,IAAiC,GAAjC,GAAuC,GAAzD;EACA,MAAMC,IAAI,GAAGL,gBAAgB,CAACC,KAAjB,CAAuBE,SAAvB,EAAkC,CAAlC,CAAb;;EACA,IAAI,CAACE,IAAL,EAAW;IACP,MAAM,IAAIH,cAAJ,CACF,wCADE,EAEF,0BAFE,EAGF;MACIH,KAAK,EAAEC;IADX,CAHE,CAAN;EAOH;;EACD,MAAMM,YAAY,GAAGD,IAAI,CAACJ,KAAL,CAAW,GAAX,CAArB;EACA,MAAM,CAACM,KAAD,EAAQC,OAAR,IAAmBF,YAAzB;;EACA,IAAIC,KAAK,KAAKE,SAAV,IAAuBD,OAAO,KAAKC,SAAnC,IAAgDH,YAAY,CAACI,MAAb,KAAwB,CAA5E,EAA+E;IAC3E,MAAM,IAAIR,cAAJ,CACF,gDADE,EAEF,0BAFE,EAGF;MACIH,KAAK,EAAEM;IADX,CAHE,CAAN;EAOH;AACJ,CAjCD;AAkCA;AACA;AACA;AACA;;;AACO,MAAMM,eAAe,GAAG,IAAIC,0BAAJ,CAAsB;EACjDC,IAAI,EAAE,WAD2C;EAEjDC,WAAW,EAAE,+CAFoC;EAGjDC,UAAU,EAAEhB,KAAK,IAAI;IACjB;IACAiB,gCAAA,CAAiBD,UAAjB,CAA4BhB,KAA5B;;IACAD,gBAAgB,CAACC,KAAD,CAAhB;IACA,OAAOA,KAAP;EACH,CARgD;EASjDkB,SAAS,EAAElB,KAAK,IAAI;IAChB,OAAOA,KAAP;EACH;AAXgD,CAAtB,CAAxB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["JsonScalar","JSONResolver"],"sources":["JsonScalar.ts"],"sourcesContent":["import { JSONResolver } from \"graphql-scalars\";\nexport const JsonScalar = JSONResolver;\n"],"mappings":";;;;;;;AAAA;;AACO,MAAMA,UAAU,GAAGC,4BAAnB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LongScalar","LongResolver"],"sources":["LongScalar.ts"],"sourcesContent":["import { LongResolver } from \"graphql-scalars\";\nexport const LongScalar = LongResolver;\n"],"mappings":";;;;;;;AAAA;;AACO,MAAMA,UAAU,GAAGC,4BAAnB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["parseValue","value","String","match","WebinyError","undefined","isNaN","parseFloat","Number","GraphQLScalarType","name","description","serialize","ex","console","log","message","code","data","parseLiteral","ast","kind","Kind","INT","FLOAT","Error"],"sources":["NumberScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport { Kind } from \"graphql/language\";\nimport WebinyError from \"@webiny/error\";\n\nconst parseValue = (value: any) => {\n if (String(value).match(/^0x/) !== null) {\n throw new WebinyError(\"Value sent must be a non-hex number.\", \"INVALID_VALUE\", {\n value\n });\n } else if (typeof value === \"number\") {\n return value;\n } else if (value === null || value === undefined) {\n return null;\n } else if (isNaN(value) === true) {\n throw new WebinyError(\"Value sent must be a number.\", \"INVALID_VALUE\", {\n value\n });\n }\n return parseFloat(value);\n};\n\nexport const Number = new GraphQLScalarType({\n name: \"Number\",\n description: \"A custom input type to be used with numbers. Supports Int and Float.\",\n serialize: (value: any) => {\n try {\n return parseValue(value);\n } catch (ex) {\n console.log({\n message: \"Value sent must be a number.\",\n code: \"INVALID_VALUE\",\n data: {\n value\n }\n });\n return null;\n }\n },\n parseValue,\n parseLiteral: (ast: any) => {\n if (ast.kind === Kind.INT || ast.kind === Kind.FLOAT) {\n return ast.value;\n }\n\n throw new Error(`Expected type Number, found {${ast.value}}`);\n }\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,UAAU,GAAIC,KAAD,IAAgB;EAC/B,IAAIC,MAAM,CAACD,KAAD,CAAN,CAAcE,KAAd,CAAoB,KAApB,MAA+B,IAAnC,EAAyC;IACrC,MAAM,IAAIC,cAAJ,CAAgB,sCAAhB,EAAwD,eAAxD,EAAyE;MAC3EH;IAD2E,CAAzE,CAAN;EAGH,CAJD,MAIO,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAClC,OAAOA,KAAP;EACH,CAFM,MAEA,IAAIA,KAAK,KAAK,IAAV,IAAkBA,KAAK,KAAKI,SAAhC,EAA2C;IAC9C,OAAO,IAAP;EACH,CAFM,MAEA,IAAIC,KAAK,CAACL,KAAD,CAAL,KAAiB,IAArB,EAA2B;IAC9B,MAAM,IAAIG,cAAJ,CAAgB,8BAAhB,EAAgD,eAAhD,EAAiE;MACnEH;IADmE,CAAjE,CAAN;EAGH;;EACD,OAAOM,UAAU,CAACN,KAAD,CAAjB;AACH,CAfD;;AAiBO,MAAMO,MAAM,GAAG,IAAIC,0BAAJ,CAAsB;EACxCC,IAAI,EAAE,QADkC;EAExCC,WAAW,EAAE,sEAF2B;EAGxCC,SAAS,EAAGX,KAAD,IAAgB;IACvB,IAAI;MACA,OAAOD,UAAU,CAACC,KAAD,CAAjB;IACH,CAFD,CAEE,OAAOY,EAAP,EAAW;MACTC,OAAO,CAACC,GAAR,CAAY;QACRC,OAAO,EAAE,8BADD;QAERC,IAAI,EAAE,eAFE;QAGRC,IAAI,EAAE;UACFjB;QADE;MAHE,CAAZ;MAOA,OAAO,IAAP;IACH;EACJ,CAhBuC;EAiBxCD,UAjBwC;EAkBxCmB,YAAY,EAAGC,GAAD,IAAc;IACxB,IAAIA,GAAG,CAACC,IAAJ,KAAaC,cAAA,CAAKC,GAAlB,IAAyBH,GAAG,CAACC,IAAJ,KAAaC,cAAA,CAAKE,KAA/C,EAAsD;MAClD,OAAOJ,GAAG,CAACnB,KAAX;IACH;;IAED,MAAM,IAAIwB,KAAJ,CAAW,gCAA+BL,GAAG,CAACnB,KAAM,GAApD,CAAN;EACH;AAxBuC,CAAtB,CAAf"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isMongoId","value","test","Error","RefInput","GraphQLScalarType","name","description","serialize","id","parseValue","parseLiteral","ast","kind","i","fields","length"],"sources":["RefInputScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\n\nconst isMongoId = (value: any): string => {\n if (/^[0-9a-fA-F]{24}$/.test(value)) {\n return value;\n }\n\n throw new Error(\"Must be a valid Mongo ID!\");\n};\n\nexport const RefInput = new GraphQLScalarType({\n name: \"RefInput\",\n description:\n \"A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.\",\n serialize: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n return typeof value === \"string\" ? value : value.id;\n },\n parseValue: value => {\n if (!value || value.id === null) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return isMongoId(value);\n }\n\n if (\"id\" in value) {\n return isMongoId(value.id);\n }\n\n throw new Error(\"Invalid RefInput value!\");\n },\n parseLiteral: ast => {\n if (ast.kind === \"StringValue\") {\n return isMongoId(ast.value);\n }\n\n if (ast.kind === \"ObjectValue\") {\n for (let i = 0; i < ast.fields.length; i++) {\n const { name, value } = ast.fields[i];\n if (name.value === \"id\") {\n // @ts-ignore\n return isMongoId(value.value);\n }\n }\n }\n\n throw new Error(\"Invalid RefInput value!\");\n }\n});\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,SAAS,GAAIC,KAAD,IAAwB;EACtC,IAAI,oBAAoBC,IAApB,CAAyBD,KAAzB,CAAJ,EAAqC;IACjC,OAAOA,KAAP;EACH;;EAED,MAAM,IAAIE,KAAJ,CAAU,2BAAV,CAAN;AACH,CAND;;AAQO,MAAMC,QAAQ,GAAG,IAAIC,0BAAJ,CAAsB;EAC1CC,IAAI,EAAE,UADoC;EAE1CC,WAAW,EACP,oGAHsC;EAI1CC,SAAS,EAAEP,KAAK,IAAI;IAChB,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACQ,EAAN,KAAa,IAA3B,EAAiC;MAC7B,OAAO,IAAP;IACH;;IAED,OAAO,OAAOR,KAAP,KAAiB,QAAjB,GAA4BA,KAA5B,GAAoCA,KAAK,CAACQ,EAAjD;EACH,CAVyC;EAW1CC,UAAU,EAAET,KAAK,IAAI;IACjB,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACQ,EAAN,KAAa,IAA3B,EAAiC;MAC7B,OAAO,IAAP;IACH;;IAED,IAAI,OAAOR,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOD,SAAS,CAACC,KAAD,CAAhB;IACH;;IAED,IAAI,QAAQA,KAAZ,EAAmB;MACf,OAAOD,SAAS,CAACC,KAAK,CAACQ,EAAP,CAAhB;IACH;;IAED,MAAM,IAAIN,KAAJ,CAAU,yBAAV,CAAN;EACH,CAzByC;EA0B1CQ,YAAY,EAAEC,GAAG,IAAI;IACjB,IAAIA,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;MAC5B,OAAOb,SAAS,CAACY,GAAG,CAACX,KAAL,CAAhB;IACH;;IAED,IAAIW,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;MAC5B,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,GAAG,CAACG,MAAJ,CAAWC,MAA/B,EAAuCF,CAAC,EAAxC,EAA4C;QACxC,MAAM;UAAER,IAAF;UAAQL;QAAR,IAAkBW,GAAG,CAACG,MAAJ,CAAWD,CAAX,CAAxB;;QACA,IAAIR,IAAI,CAACL,KAAL,KAAe,IAAnB,EAAyB;UACrB;UACA,OAAOD,SAAS,CAACC,KAAK,CAACA,KAAP,CAAhB;QACH;MACJ;IACJ;;IAED,MAAM,IAAIE,KAAJ,CAAU,yBAAV,CAAN;EACH;AA1CyC,CAAtB,CAAjB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["re","parseTime","value","match","WebinyError","parsed","split","map","Number","length","hours","minutes","seconds","convertToTime","String","padStart","TimeScalar","GraphQLScalarType","name","description","serialize","parseValue"],"sources":["TimeScalar.ts"],"sourcesContent":["import { GraphQLScalarType } from \"graphql\";\nimport WebinyError from \"@webiny/error\";\n\nconst re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;\n\nconst parseTime = (value?: string) => {\n if (!value || value.match(re) === null) {\n throw new WebinyError(\"Value does not look like time.\", \"TIME_VALIDATION_ERROR\", { value });\n }\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new WebinyError(`Could not parse the value.`, \"TIME_VALIDATION_ERROR\", { value });\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new WebinyError(`There cannot be more than 24 hours.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (minutes >= 60) {\n throw new WebinyError(`There cannot be more than 59 minutes.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n } else if (seconds >= 60) {\n throw new WebinyError(`There cannot be more than 59 seconds.`, \"TIME_VALIDATION_ERROR\", {\n value\n });\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n\nconst convertToTime = (value: string): string => {\n const { hours, minutes, seconds } = parseTime(value);\n return `${String(hours).padStart(2, \"0\")}:${String(minutes).padStart(2, \"0\")}:${String(\n seconds\n ).padStart(2, \"0\")}`;\n};\n\nexport const TimeScalar = new GraphQLScalarType({\n name: \"Time\",\n description: \"A custom type to support time-only input.\",\n // sending to client\n serialize: convertToTime,\n // received from client\n parseValue: convertToTime\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA,MAAMA,EAAE,GAAG,uCAAX;;AAEA,MAAMC,SAAS,GAAIC,KAAD,IAAoB;EAClC,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACC,KAAN,CAAYH,EAAZ,MAAoB,IAAlC,EAAwC;IACpC,MAAM,IAAII,cAAJ,CAAgB,gCAAhB,EAAkD,uBAAlD,EAA2E;MAAEF;IAAF,CAA3E,CAAN;EACH;;EACD,MAAMG,MAAM,GAAGH,KAAK,CAACI,KAAN,CAAY,GAAZ,EAAiBC,GAAjB,CAAqBC,MAArB,CAAf;;EACA,IAAIH,MAAM,CAACI,MAAP,GAAgB,CAApB,EAAuB;IACnB,MAAM,IAAIL,cAAJ,CAAiB,4BAAjB,EAA8C,uBAA9C,EAAuE;MAAEF;IAAF,CAAvE,CAAN;EACH;;EACD,MAAM,CAACQ,KAAD,EAAQC,OAAR,EAAiBC,OAAO,GAAG,CAA3B,IAAgCP,MAAtC;;EACA,IAAIK,KAAK,IAAI,EAAb,EAAiB;IACb,MAAM,IAAIN,cAAJ,CAAiB,qCAAjB,EAAuD,uBAAvD,EAAgF;MAClFF;IADkF,CAAhF,CAAN;EAGH,CAJD,MAIO,IAAIS,OAAO,IAAI,EAAf,EAAmB;IACtB,MAAM,IAAIP,cAAJ,CAAiB,uCAAjB,EAAyD,uBAAzD,EAAkF;MACpFF;IADoF,CAAlF,CAAN;EAGH,CAJM,MAIA,IAAIU,OAAO,IAAI,EAAf,EAAmB;IACtB,MAAM,IAAIR,cAAJ,CAAiB,uCAAjB,EAAyD,uBAAzD,EAAkF;MACpFF;IADoF,CAAlF,CAAN;EAGH;;EACD,OAAO;IACHQ,KADG;IAEHC,OAFG;IAGHC;EAHG,CAAP;AAKH,CA3BD;;AA6BA,MAAMC,aAAa,GAAIX,KAAD,IAA2B;EAC7C,MAAM;IAAEQ,KAAF;IAASC,OAAT;IAAkBC;EAAlB,IAA8BX,SAAS,CAACC,KAAD,CAA7C;EACA,OAAQ,GAAEY,MAAM,CAACJ,KAAD,CAAN,CAAcK,QAAd,CAAuB,CAAvB,EAA0B,GAA1B,CAA+B,IAAGD,MAAM,CAACH,OAAD,CAAN,CAAgBI,QAAhB,CAAyB,CAAzB,EAA4B,GAA5B,CAAiC,IAAGD,MAAM,CAClFF,OADkF,CAAN,CAE9EG,QAF8E,CAErE,CAFqE,EAElE,GAFkE,CAE7D,EAFnB;AAGH,CALD;;AAOO,MAAMC,UAAU,GAAG,IAAIC,0BAAJ,CAAsB;EAC5CC,IAAI,EAAE,MADsC;EAE5CC,WAAW,EAAE,2CAF+B;EAG5C;EACAC,SAAS,EAAEP,aAJiC;EAK5C;EACAQ,UAAU,EAAER;AANgC,CAAtB,CAAnB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AnyScalar\";\nexport * from \"./DateScalar\";\nexport * from \"./DateTimeScalar\";\nexport * from \"./DateTimeZScalar\";\nexport * from \"./JsonScalar\";\nexport * from \"./LongScalar\";\nexport * from \"./NumberScalar\";\nexport * from \"./RefInputScalar\";\nexport * from \"./TimeScalar\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
10
  var _boolean = require("boolean");
13
11
 
14
12
  var _createGraphQLSchema = require("./createGraphQLSchema");
@@ -17,61 +15,46 @@ var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
17
15
 
18
16
  var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
19
17
 
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
18
+ var _handler = require("@webiny/handler");
19
+
20
+ const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
21
21
 
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
22
+ /**
23
+ * TODO Until we figure out how to better convert incoming body, we will leave it as any.
24
+ */
23
25
 
24
- const DEFAULT_HEADERS = {
25
- "Content-Type": "application/json",
26
- "Access-Control-Allow-Origin": "*",
27
- "Access-Control-Allow-Headers": "*",
28
- "Access-Control-Allow-Methods": "OPTIONS,POST"
26
+ const createRequestBody = body => {
27
+ return typeof body === "string" ? JSON.parse(body) : body;
29
28
  };
30
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
31
29
 
32
30
  var _default = (options = {}) => {
33
- let schema;
31
+ let schema = undefined;
34
32
  const debug = (0, _boolean.boolean)(options.debug);
35
- return [...(debug ? (0, _debugPlugins.default)() : []), {
36
- type: "handler",
37
- name: "handler-graphql",
38
-
39
- async handle(context, next) {
40
- const {
41
- http
42
- } = context;
43
-
44
- if (!http) {
45
- return next();
46
- }
47
-
48
- if (http.request.method === "OPTIONS") {
49
- return http.response({
50
- statusCode: 204,
51
- headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
52
- "Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
53
- })
54
- });
55
- }
56
-
57
- if (http.request.method !== "POST") {
58
- return next();
59
- }
60
-
33
+ const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
34
+ const route = new _handler.RoutePlugin(async ({
35
+ onPost,
36
+ onOptions,
37
+ context
38
+ }) => {
39
+ onOptions(path, async (_, reply) => {
40
+ return reply.status(204).headers({
41
+ "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
42
+ }).send({});
43
+ });
44
+ onPost(path, async (request, reply) => {
61
45
  if (!schema) {
62
46
  schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
63
47
  }
64
48
 
65
- const body = JSON.parse(http.request.body);
49
+ const body = createRequestBody(request.body);
66
50
  const result = await (0, _processRequestBody.default)(body, schema, context);
67
- return http.response({
68
- body: JSON.stringify(result),
69
- statusCode: 200,
70
- headers: DEFAULT_HEADERS
71
- });
72
- }
73
-
74
- }];
51
+ return reply.status(200).send(result);
52
+ });
53
+ });
54
+ route.name = "handler.graphql.route.default";
55
+ return [...(debug ? (0, _debugPlugins.default)() : []), {
56
+ type: "wcp-telemetry-tracker"
57
+ }, route];
75
58
  };
76
59
 
77
60
  exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createRequestBody","body","JSON","parse","options","schema","undefined","debug","boolean","path","route","RoutePlugin","onPost","onOptions","context","_","reply","status","headers","send","request","createGraphQLSchema","result","processRequestBody","name","debugPlugins","type"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema } from \"./createGraphQLSchema\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\n/**\n * TODO Until we figure out how to better convert incoming body, we will leave it as any.\n */\nconst createRequestBody = (body: any): any => {\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({});\n });\n onPost(path, async (request, reply) => {\n if (!schema) {\n schema = createGraphQLSchema(context);\n }\n const body = createRequestBody(request.body);\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAEA;;AAEA,MAAMA,qBAAqB,GAAG,QAA9B,C,CAAwC;;AAExC;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAIC,IAAD,IAAoB;EAC1C,OAAO,OAAOA,IAAP,KAAgB,QAAhB,GAA2BC,IAAI,CAACC,KAAL,CAAWF,IAAX,CAA3B,GAA8CA,IAArD;AACH,CAFD;;eAIe,CAACG,OAA8B,GAAG,EAAlC,KAA2D;EACtE,IAAIC,MAAiC,GAAGC,SAAxC;EAEA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,EAAQJ,OAAO,CAACG,KAAhB,CAAd;EAEA,MAAME,IAAI,GAAG,CAAAL,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEK,IAAT,KAAiB,UAA9B;EAEA,MAAMC,KAAK,GAAG,IAAIC,oBAAJ,CAAgB,OAAO;IAAEC,MAAF;IAAUC,SAAV;IAAqBC;EAArB,CAAP,KAA0C;IACpED,SAAS,CAACJ,IAAD,EAAO,OAAOM,CAAP,EAAUC,KAAV,KAAoB;MAChC,OAAOA,KAAK,CACPC,MADE,CACK,GADL,EAEFC,OAFE,CAEM;QACL,iBAAkB,mBAAkBnB,qBAAsB;MADrD,CAFN,EAKFoB,IALE,CAKG,EALH,CAAP;IAMH,CAPQ,CAAT;IAQAP,MAAM,CAACH,IAAD,EAAO,OAAOW,OAAP,EAAgBJ,KAAhB,KAA0B;MACnC,IAAI,CAACX,MAAL,EAAa;QACTA,MAAM,GAAG,IAAAgB,wCAAA,EAAoBP,OAApB,CAAT;MACH;;MACD,MAAMb,IAAI,GAAGD,iBAAiB,CAACoB,OAAO,CAACnB,IAAT,CAA9B;MACA,MAAMqB,MAAM,GAAG,MAAM,IAAAC,2BAAA,EAAmBtB,IAAnB,EAAyBI,MAAzB,EAAiCS,OAAjC,CAArB;MACA,OAAOE,KAAK,CAACC,MAAN,CAAa,GAAb,EAAkBE,IAAlB,CAAuBG,MAAvB,CAAP;IACH,CAPK,CAAN;EAQH,CAjBa,CAAd;EAmBAZ,KAAK,CAACc,IAAN,GAAa,+BAAb;EAEA,OAAO,CACH,IAAIjB,KAAK,GAAG,IAAAkB,qBAAA,GAAH,GAAoB,EAA7B,CADG,EAEH;IACIC,IAAI,EAAE;EADV,CAFG,EAKHhB,KALG,CAAP;AAOH,C"}
@@ -1,3 +1,2 @@
1
- import { Context } from "@webiny/handler/types";
2
- import { HttpContext } from "@webiny/handler-http/types";
3
- export declare const createGraphQLSchema: (context: Context<HttpContext>) => import("graphql").GraphQLSchema;
1
+ import { Context } from "@webiny/api/types";
2
+ export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
@@ -15,9 +15,9 @@ var _schema = require("@graphql-tools/schema");
15
15
 
16
16
  var _builtInTypes = require("./builtInTypes");
17
17
 
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
19
 
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
21
 
22
22
  const createGraphQLSchema = context => {
23
23
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
@@ -51,7 +51,14 @@ const createGraphQLSchema = context => {
51
51
 
52
52
  for (let i = 0; i < gqlPlugins.length; i++) {
53
53
  const plugin = gqlPlugins[i];
54
- typeDefs.push(plugin.schema.typeDefs);
54
+ /**
55
+ * TODO @ts-refactor
56
+ * Figure out correct types on typeDefs and resolvers
57
+ */
58
+ // @ts-ignore
59
+
60
+ typeDefs.push(plugin.schema.typeDefs); // @ts-ignore
61
+
55
62
  resolvers.push(plugin.schema.resolvers);
56
63
  }
57
64
 
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","gqlPlugins","i","length","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport {\n RefInput,\n Number as NumberScalar,\n Any as AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { GraphQLScalarType } from \"graphql/type/definition\";\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n const typeDefs = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n `\n ];\n\n const resolvers = [\n {\n ...scalars.reduce((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {} as Record<string, GraphQLScalarType>),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const gqlPlugins = context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n for (let i = 0; i < gqlPlugins.length; i++) {\n const plugin = gqlPlugins[i];\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;;;;;AAYO,MAAMA,mBAAmB,GAAIC,OAAD,IAAsB;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAR,CACXC,MADW,CACiB,gBADjB,EAEXC,GAFW,CAEPC,IAAI,IAAIA,IAAI,CAACC,MAFN,CAAhB;EAIA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAA,CAAI;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,GAAR,CAAYE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAA5C,EAA+CC,IAA/C,CAAoD,GAApD,CAAyD;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAbqB,CAAjB;EAgBA,MAAMC,SAAS,GAAG,iCAEPV,OAAO,CAACW,MAAR,CAAe,CAACC,GAAD,EAAMC,CAAN,KAAY;IAC1BD,GAAG,CAACC,CAAC,CAACL,IAAH,CAAH,GAAcK,CAAd;IACA,OAAOD,GAAP;EACH,CAHE,EAGA,EAHA,CAFO;IAMVE,IAAI,EAAEC,wBANI;IAOVC,IAAI,EAAEC,wBAPI;IAQVC,QAAQ,EAARA,sBARU;IASVC,MAAM,EAAEC,oBATE;IAUVC,GAAG,EAAEC,iBAVK;IAWVC,QAAQ,EAAEC,4BAXA;IAYVC,IAAI,EAAEC,wBAZI;IAaVC,IAAI,EAAEC;EAbI,GAAlB;EAiBA,MAAMC,UAAU,GAAG9B,OAAO,CAACE,OAAR,CAAgBC,MAAhB,CAA4C,gBAA5C,CAAnB;;EACA,KAAK,IAAI4B,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,EAAxC,EAA4C;IACxC,MAAME,MAAM,GAAGH,UAAU,CAACC,CAAD,CAAzB;IACA;AACR;AACA;AACA;IACQ;;IACAxB,QAAQ,CAAC2B,IAAT,CAAcD,MAAM,CAACE,MAAP,CAAc5B,QAA5B,EAPwC,CAQxC;;IACAI,SAAS,CAACuB,IAAV,CAAeD,MAAM,CAACE,MAAP,CAAcxB,SAA7B;EACH;;EAED,OAAO,IAAAyB,4BAAA,EAAqB;IACxB7B,QADwB;IAExBI,SAFwB;IAGxB0B,8BAA8B,EAAE;EAHR,CAArB,CAAP;AAKH,CAxDM"}
package/debugPlugins.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin } from "./types";
2
- import { ContextInterface, ContextPlugin } from "@webiny/handler/types";
3
- interface DebugContext extends ContextInterface {
1
+ import { GraphQLAfterQueryPlugin } from "./types";
2
+ import { Context } from "@webiny/api/types";
3
+ import { ContextPlugin } from "@webiny/api";
4
+ interface Log {
5
+ method: string;
6
+ args: any;
7
+ }
8
+ interface DebugContext extends Context {
4
9
  debug: {
5
- logs?: {
6
- method: string;
7
- args: any;
8
- }[];
10
+ logs?: Log[];
9
11
  };
10
12
  }
11
- declare const _default: () => (ContextPlugin<DebugContext, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>> | GraphQLBeforeQueryPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
13
+ declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
12
14
  export default _default;
package/debugPlugins.js CHANGED
@@ -7,31 +7,24 @@ exports.default = void 0;
7
7
 
8
8
  var _interceptConsole = require("./interceptConsole");
9
9
 
10
- var _default = () => [{
11
- type: "context",
10
+ var _api = require("@webiny/api");
12
11
 
13
- apply(context) {
14
- context.debug = context.debug || {};
15
- context.debug.logs = [];
16
- (0, _interceptConsole.interceptConsole)((method, args) => {
17
- context.debug.logs.push({
18
- method,
19
- args
20
- });
21
- });
12
+ var _default = () => [new _api.ContextPlugin(async context => {
13
+ if (!context.debug) {
14
+ context.debug = {};
22
15
  }
23
16
 
24
- }, {
25
- type: "graphql-before-query",
26
-
27
- apply({
28
- context
29
- }) {
30
- // Empty logs
17
+ if (!context.debug.logs) {
31
18
  context.debug.logs = [];
32
19
  }
33
20
 
34
- }, {
21
+ (0, _interceptConsole.interceptConsole)((method, args) => {
22
+ context.debug.logs.push({
23
+ method,
24
+ args
25
+ });
26
+ });
27
+ }), {
35
28
  type: "graphql-after-query",
36
29
 
37
30
  apply({
@@ -39,8 +32,12 @@ var _default = () => [{
39
32
  context
40
33
  }) {
41
34
  result["extensions"] = {
42
- console: context.debug.logs || []
35
+ console: [...(context.debug.logs || [])]
43
36
  };
37
+
38
+ if (context.debug.logs) {
39
+ context.debug.logs.length = 0;
40
+ }
44
41
  }
45
42
 
46
43
  }];
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;;AAAA;;AAGA;;eAYe,MAAM,CACjB,IAAIA,kBAAJ,CAAgC,MAAMC,OAAN,IAAiB;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAb,EAAoB;IAChBD,OAAO,CAACC,KAAR,GAAgB,EAAhB;EACH;;EAED,IAAI,CAACD,OAAO,CAACC,KAAR,CAAcC,IAAnB,EAAyB;IACrBF,OAAO,CAACC,KAAR,CAAcC,IAAd,GAAqB,EAArB;EACH;;EAED,IAAAC,kCAAA,EAAiB,CAACC,MAAD,EAASC,IAAT,KAAkB;IAC9BL,OAAO,CAACC,KAAR,CAAcC,IAAf,CAA8BI,IAA9B,CAAmC;MAAEF,MAAF;MAAUC;IAAV,CAAnC;EACH,CAFD;AAGH,CAZD,CADiB,EAcjB;EACIE,IAAI,EAAE,qBADV;;EAEIC,KAAK,CAAC;IAAEC,MAAF;IAAUT;EAAV,CAAD,EAAsB;IACvBS,MAAM,CAAC,YAAD,CAAN,GAAuB;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAR,CAAcC,IAAd,IAAsB,EAA1B,CAAD;IAAX,CAAvB;;IACA,IAAIF,OAAO,CAACC,KAAR,CAAcC,IAAlB,EAAwB;MACpBF,OAAO,CAACC,KAAR,CAAcC,IAAd,CAAmBS,MAAnB,GAA4B,CAA5B;IACH;EACJ;;AAPL,CAdiB,C"}
package/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Error from "@webiny/error";
2
- export declare class NotFoundError extends Error {
1
+ import WebinyError from "@webiny/error";
2
+ export declare class NotFoundError extends WebinyError {
3
3
  constructor(message?: string);
4
4
  }
package/errors.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;;;AAAA;;AAEO,MAAMA,aAAN,SAA4BC,cAA5B,CAAwC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAX,EAAyB;IAChC,MAAMA,OAAN,EAAe,WAAf;EACH;;AAH0C"}
package/index.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  import { HandlerGraphQLOptions } from "./types";
2
- import { Context } from "@webiny/handler/types";
2
+ import { Context } from "@webiny/api/types";
3
3
  import { GraphQLFieldResolver } from "./types";
4
+ /**
5
+ * Can be anything.
6
+ * TODO: Figure out if required at all.
7
+ */
8
+ interface Callable {
9
+ (params: any): any;
10
+ }
4
11
  export * from "./errors";
5
12
  export * from "./responses";
6
13
  declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
7
14
  export default _default;
8
- export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
9
- export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
15
+ export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) => (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) => GraphQLFieldResolver<TSource, TArgs, TContext>;
16
+ export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) => (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) => GraphQLFieldResolver<TSource, TArgs, TContext>;
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["options","createGraphQLHandler","pipe","fns","resolver","reduce","v","f","compose","reduceRight"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\nimport { Context } from \"@webiny/api/types\";\nimport { GraphQLFieldResolver } from \"./types\";\n\n/**\n * Can be anything.\n * TODO: Figure out if required at all.\n */\ninterface Callable {\n (params: any): any;\n}\nexport * from \"./errors\";\nexport * from \"./responses\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n\nexport const pipe =\n <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) =>\n (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) =>\n fns.reduce((v, f) => f(v), resolver);\n\nexport const compose =\n <TSource = any, TArgs = Record<string, any>, TContext = Context>(...fns: Callable[]) =>\n (resolver: GraphQLFieldResolver<TSource, TArgs, TContext>) =>\n fns.reduceRight((v, f) => f(v), resolver);\n"],"mappings":";;;;;;;;;;;;;AACA;;AAWA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;eAEe,CAACA,OAA8B,GAAG,EAAlC,KAAyC,CAAC,IAAAC,6BAAA,EAAqBD,OAArB,CAAD,C;;;;AAEjD,MAAME,IAAI,GACb,CAAiE,GAAGC,GAApE,KACCC,QAAD,IACID,GAAG,CAACE,MAAJ,CAAW,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAAC,CAACD,CAAD,CAAtB,EAA2BF,QAA3B,CAHD;;;;AAKA,MAAMI,OAAO,GAChB,CAAiE,GAAGL,GAApE,KACCC,QAAD,IACID,GAAG,CAACM,WAAJ,CAAgB,CAACH,CAAD,EAAIC,CAAJ,KAAUA,CAAC,CAACD,CAAD,CAA3B,EAAgCF,QAAhC,CAHD"}
@@ -1 +1,5 @@
1
- export declare const interceptConsole: (callback: any) => void;
1
+ interface InterceptConsoleCallable {
2
+ (method: string, args: any[]): void;
3
+ }
4
+ export declare const interceptConsole: (callback: InterceptConsoleCallable) => void;
5
+ export {};
@@ -10,19 +10,23 @@ const skipOriginal = ["table"];
10
10
 
11
11
  const restoreOriginalMethods = () => {
12
12
  for (const method of consoleMethods) {
13
+ // @ts-ignore
13
14
  console[method] = originalMethods[method];
14
15
  }
15
16
  };
16
17
 
17
18
  const interceptConsole = callback => {
19
+ // @ts-ignore
18
20
  if (console["__WEBINY__"] === true) {
19
21
  restoreOriginalMethods();
20
- }
22
+ } // @ts-ignore
23
+
21
24
 
22
25
  console["__WEBINY__"] = true;
23
26
 
24
27
  for (const method of consoleMethods) {
25
- originalMethods[method] = console[method];
28
+ // @ts-ignore
29
+ originalMethods[method] = console[method]; // @ts-ignore
26
30
 
27
31
  console[method] = (...args) => {
28
32
  callback(method, args);
@@ -0,0 +1 @@
1
+ {"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-ignore\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-ignore\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-ignore\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-ignore\n originalMethods[method] = console[method];\n // @ts-ignore\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CACnB,QADmB,EAEnB,OAFmB,EAGnB,KAHmB,EAInB,OAJmB,EAKnB,OALmB,EAMnB,gBANmB,EAOnB,UAPmB,EAQnB,MARmB,EASnB,KATmB,EAUnB,OAVmB,EAWnB,MAXmB,CAAvB;AAcA,MAAMC,eAAoC,GAAG,EAA7C;AACA,MAAMC,YAAsB,GAAG,CAAC,OAAD,CAA/B;;AAEA,MAAMC,sBAAsB,GAAG,MAAM;EACjC,KAAK,MAAMC,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAK,OAAO,CAACD,MAAD,CAAP,GAAkBH,eAAe,CAACG,MAAD,CAAjC;EACH;AACJ,CALD;;AAWO,MAAME,gBAAgB,GAAIC,QAAD,IAAwC;EACpE;EACA,IAAIF,OAAO,CAAC,YAAD,CAAP,KAA0B,IAA9B,EAAoC;IAChCF,sBAAsB;EACzB,CAJmE,CAMpE;;;EACAE,OAAO,CAAC,YAAD,CAAP,GAAwB,IAAxB;;EAEA,KAAK,MAAMD,MAAX,IAAqBJ,cAArB,EAAqC;IACjC;IACAC,eAAe,CAACG,MAAD,CAAf,GAA0BC,OAAO,CAACD,MAAD,CAAjC,CAFiC,CAGjC;;IACAC,OAAO,CAACD,MAAD,CAAP,GAAkB,CAAC,GAAGI,IAAJ,KAAa;MAC3BD,QAAQ,CAACH,MAAD,EAASI,IAAT,CAAR;;MACA,IAAIN,YAAY,CAACO,QAAb,CAAsBL,MAAtB,CAAJ,EAAmC;QAC/B;MACH;;MACDH,eAAe,CAACG,MAAD,CAAf,CAAwB,GAAGI,IAA3B;IACH,CAND;EAOH;AACJ,CArBM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-graphql",
3
- "version": "0.0.0-mt-3",
3
+ "version": "0.0.0-unstable.8c4d9f045a",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,28 +14,28 @@
14
14
  "Adrian Smijulj <adrian@webiny.com>"
15
15
  ],
16
16
  "dependencies": {
17
- "@babel/runtime": "7.15.4",
17
+ "@babel/runtime": "7.18.9",
18
18
  "@graphql-tools/schema": "7.1.5",
19
- "@webiny/error": "0.0.0-mt-3",
20
- "@webiny/handler": "0.0.0-mt-3",
21
- "@webiny/handler-http": "0.0.0-mt-3",
22
- "@webiny/plugins": "0.0.0-mt-3",
23
- "boolean": "3.1.4",
24
- "graphql": "14.7.0",
19
+ "@webiny/api": "0.0.0-unstable.8c4d9f045a",
20
+ "@webiny/error": "0.0.0-unstable.8c4d9f045a",
21
+ "@webiny/handler": "0.0.0-unstable.8c4d9f045a",
22
+ "@webiny/plugins": "0.0.0-unstable.8c4d9f045a",
23
+ "boolean": "3.2.0",
24
+ "graphql": "15.8.0",
25
25
  "graphql-scalars": "1.12.0",
26
- "graphql-tag": "2.12.5"
26
+ "graphql-tag": "2.12.6"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/cli": "^7.5.5",
30
- "@babel/core": "^7.5.5",
31
- "@babel/preset-env": "^7.5.5",
32
- "@webiny/cli": "^0.0.0-mt-3",
33
- "@webiny/handler-args": "^0.0.0-mt-3",
34
- "@webiny/project-utils": "^0.0.0-mt-3",
35
- "jest": "^26.6.3",
29
+ "@babel/cli": "^7.16.0",
30
+ "@babel/core": "^7.16.0",
31
+ "@babel/preset-env": "^7.16.4",
32
+ "@webiny/cli": "^0.0.0-unstable.8c4d9f045a",
33
+ "@webiny/handler-aws": "^0.0.0-unstable.8c4d9f045a",
34
+ "@webiny/project-utils": "^0.0.0-unstable.8c4d9f045a",
35
+ "jest": "^28.1.0",
36
36
  "jest-mock-console": "^1.0.0",
37
37
  "rimraf": "^3.0.2",
38
- "typescript": "^4.1.3"
38
+ "typescript": "4.7.4"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public",
@@ -45,5 +45,5 @@
45
45
  "build": "yarn webiny run build",
46
46
  "watch": "yarn webiny run watch"
47
47
  },
48
- "gitHead": "ebea815be2be99404591cba465cc1fe88355bd48"
48
+ "gitHead": "5f904a53a5956269bd80a9c084cc04f92b824d36"
49
49
  }
@@ -1,12 +1,12 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
2
  import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
3
- import { Context } from "@webiny/handler/types";
3
+ import { Context } from "@webiny/api/types";
4
4
  export interface GraphQLSchemaPluginConfig<TContext> {
5
5
  typeDefs?: Types;
6
6
  resolvers?: Resolvers<TContext>;
7
7
  }
8
8
  export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
9
- static readonly type = "graphql-schema";
9
+ static readonly type: string;
10
10
  private config;
11
11
  constructor(config: GraphQLSchemaPluginConfig<TContext>);
12
12
  get schema(): GraphQLSchemaDefinition<TContext>;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GraphQLSchemaPlugin","Plugin","constructor","config","schema","typeDefs","resolvers"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers, Types } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context> extends Plugin {\n public static override readonly type: string = \"graphql-schema\";\n private config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,mBAAN,SAAsDC,eAAtD,CAA6D;EAIhEC,WAAW,CAACC,MAAD,EAA8C;IACrD;IADqD;IAErD,KAAKA,MAAL,GAAcA,MAAd;EACH;;EAES,IAANC,MAAM,GAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,KAAKF,MAAL,CAAYE,QAAZ,IAAwB,EAD/B;MAEHC,SAAS,EAAE,KAAKH,MAAL,CAAYG;IAFpB,CAAP;EAIH;;AAd+D;;;8BAAvDN,mB,UACsC,gB"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./GraphQLSchemaPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,2 +1,5 @@
1
- declare const _default: (requestBody: any, schema: any, context: any) => Promise<any>;
1
+ import { ExecutionResult, GraphQLSchema } from "graphql";
2
+ import { GraphQLRequestBody } from "./types";
3
+ import { Context } from "@webiny/api/types";
4
+ declare const _default: (requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult[] | ExecutionResult>;
2
5
  export default _default;
@@ -31,19 +31,17 @@ const processRequestBody = async (body, schema, context) => {
31
31
  };
32
32
 
33
33
  var _default = async (requestBody, schema, context) => {
34
- let result;
35
-
36
- if (Array.isArray(requestBody)) {
37
- result = [];
34
+ if (Array.isArray(requestBody) === true) {
35
+ const result = [];
38
36
 
39
37
  for (let i = 0; i < requestBody.length; i++) {
40
38
  result.push(await processRequestBody(requestBody[i], schema, context));
41
39
  }
42
- } else {
43
- result = await processRequestBody(requestBody, schema, context);
40
+
41
+ return result;
44
42
  }
45
43
 
46
- return result;
44
+ return await processRequestBody(requestBody, schema, context);
47
45
  };
48
46
 
49
47
  exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["processRequestBody","body","schema","context","query","variables","operationName","plugins","byType","forEach","pl","apply","result","graphql","requestBody","Array","isArray","i","length","push"],"sources":["processRequestBody.ts"],"sourcesContent":["import { ExecutionResult, graphql, GraphQLSchema } from \"graphql\";\nimport { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin, GraphQLRequestBody } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\n\nconst processRequestBody = async (\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n) => {\n const { query, variables, operationName } = body;\n\n context.plugins\n .byType<GraphQLBeforeQueryPlugin>(\"graphql-before-query\")\n .forEach(pl => pl.apply({ body, schema, context }));\n\n const result = await graphql(schema, query, {}, context, variables, operationName);\n\n context.plugins.byType<GraphQLAfterQueryPlugin>(\"graphql-after-query\").forEach(pl => {\n pl.apply({ result, body, schema, context });\n });\n\n return result;\n};\n\nexport default async (\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult[] | ExecutionResult> => {\n if (Array.isArray(requestBody) === true) {\n const result: ExecutionResult[] = [];\n for (let i = 0; i < (requestBody as GraphQLRequestBody[]).length; i++) {\n result.push(\n await processRequestBody((requestBody as GraphQLRequestBody[])[i], schema, context)\n );\n }\n return result;\n }\n return await processRequestBody(requestBody as GraphQLRequestBody, schema, context);\n};\n"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,kBAAkB,GAAG,OACvBC,IADuB,EAEvBC,MAFuB,EAGvBC,OAHuB,KAItB;EACD,MAAM;IAAEC,KAAF;IAASC,SAAT;IAAoBC;EAApB,IAAsCL,IAA5C;EAEAE,OAAO,CAACI,OAAR,CACKC,MADL,CACsC,sBADtC,EAEKC,OAFL,CAEaC,EAAE,IAAIA,EAAE,CAACC,KAAH,CAAS;IAAEV,IAAF;IAAQC,MAAR;IAAgBC;EAAhB,CAAT,CAFnB;EAIA,MAAMS,MAAM,GAAG,MAAM,IAAAC,gBAAA,EAAQX,MAAR,EAAgBE,KAAhB,EAAuB,EAAvB,EAA2BD,OAA3B,EAAoCE,SAApC,EAA+CC,aAA/C,CAArB;EAEAH,OAAO,CAACI,OAAR,CAAgBC,MAAhB,CAAgD,qBAAhD,EAAuEC,OAAvE,CAA+EC,EAAE,IAAI;IACjFA,EAAE,CAACC,KAAH,CAAS;MAAEC,MAAF;MAAUX,IAAV;MAAgBC,MAAhB;MAAwBC;IAAxB,CAAT;EACH,CAFD;EAIA,OAAOS,MAAP;AACH,CAlBD;;eAoBe,OACXE,WADW,EAEXZ,MAFW,EAGXC,OAHW,KAIoC;EAC/C,IAAIY,KAAK,CAACC,OAAN,CAAcF,WAAd,MAA+B,IAAnC,EAAyC;IACrC,MAAMF,MAAyB,GAAG,EAAlC;;IACA,KAAK,IAAIK,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAIH,WAAD,CAAsCI,MAA1D,EAAkED,CAAC,EAAnE,EAAuE;MACnEL,MAAM,CAACO,IAAP,CACI,MAAMnB,kBAAkB,CAAEc,WAAD,CAAsCG,CAAtC,CAAD,EAA2Cf,MAA3C,EAAmDC,OAAnD,CAD5B;IAGH;;IACD,OAAOS,MAAP;EACH;;EACD,OAAO,MAAMZ,kBAAkB,CAACc,WAAD,EAAoCZ,MAApC,EAA4CC,OAA5C,CAA/B;AACH,C"}
package/responses.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- declare type ErrorResponseParams = {
1
+ export interface ErrorResponseParams {
2
+ message: string;
2
3
  code?: string;
3
- message?: string;
4
4
  data?: any;
5
- };
5
+ stack?: string | null;
6
+ }
6
7
  export declare class ErrorResponse {
7
- data: any;
8
- error: {
8
+ readonly data: null;
9
+ readonly error: {
9
10
  code: string;
10
11
  message: string;
11
- data?: any;
12
+ data: any;
13
+ stack: string | null;
12
14
  };
13
15
  constructor(params: ErrorResponseParams);
14
16
  }
@@ -16,24 +18,24 @@ export declare class NotFoundResponse extends ErrorResponse {
16
18
  constructor(message: string);
17
19
  }
18
20
  export declare class ListErrorResponse {
19
- data: null;
20
- meta: null;
21
- error: {
21
+ readonly data: null;
22
+ readonly meta: null;
23
+ readonly error: {
22
24
  code: string;
23
25
  message: string;
24
- data?: any;
26
+ data: any;
27
+ stack: string | null;
25
28
  };
26
29
  constructor(params: ErrorResponseParams);
27
30
  }
28
- export declare class Response<T extends any = any> {
29
- data: T;
30
- error: null;
31
+ export declare class Response<T = any> {
32
+ readonly data: T;
33
+ readonly error: null;
31
34
  constructor(data: T);
32
35
  }
33
- export declare class ListResponse<T extends any, M extends any> {
34
- data: Array<T>;
35
- meta: M;
36
- error: null;
36
+ export declare class ListResponse<T, M> {
37
+ readonly data: Array<T>;
38
+ readonly meta: M;
39
+ readonly error: null;
37
40
  constructor(data: Array<T>, meta?: M);
38
41
  }
39
- export {};
package/responses.js CHANGED
@@ -12,7 +12,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
12
12
  const defaultParams = {
13
13
  code: "",
14
14
  message: "",
15
- data: null
15
+ data: null,
16
+ stack: null
16
17
  };
17
18
 
18
19
  class ErrorResponse {
@@ -20,10 +21,19 @@ class ErrorResponse {
20
21
  (0, _defineProperty2.default)(this, "data", void 0);
21
22
  (0, _defineProperty2.default)(this, "error", void 0);
22
23
  this.data = null;
24
+ const debug = process.env.DEBUG === "true"; // Ensure `stack` is either `string` or `null`.
25
+
26
+ let stack = defaultParams.stack;
27
+
28
+ if (debug && params.stack) {
29
+ stack = params.stack;
30
+ }
31
+
23
32
  this.error = {
24
33
  code: params.code || defaultParams.code,
25
34
  message: params.message || defaultParams.message,
26
- data: params.data || defaultParams.data
35
+ data: params.data || defaultParams.data,
36
+ stack: stack
27
37
  };
28
38
  }
29
39
 
@@ -48,12 +58,21 @@ class ListErrorResponse {
48
58
  (0, _defineProperty2.default)(this, "data", void 0);
49
59
  (0, _defineProperty2.default)(this, "meta", void 0);
50
60
  (0, _defineProperty2.default)(this, "error", void 0);
51
- this.data = null;
52
61
  this.meta = null;
62
+ this.data = null;
63
+ const debug = process.env.DEBUG === "true"; // Ensure `stack` is either `string` or `null`.
64
+
65
+ let stack = defaultParams.stack;
66
+
67
+ if (debug && params.stack) {
68
+ stack = params.stack;
69
+ }
70
+
53
71
  this.error = {
54
72
  code: params.code || defaultParams.code,
55
73
  message: params.message || defaultParams.message,
56
- data: params.data || defaultParams.data
74
+ data: params.data || defaultParams.data,
75
+ stack: stack
57
76
  };
58
77
  }
59
78
 
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\nexport class ListResponse<T, M> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":";;;;;;;;;;;AAOA,MAAMA,aAA4C,GAAG;EACjDC,IAAI,EAAE,EAD2C;EAEjDC,OAAO,EAAE,EAFwC;EAGjDC,IAAI,EAAE,IAH2C;EAIjDC,KAAK,EAAE;AAJ0C,CAArD;;AAOO,MAAMC,aAAN,CAAoB;EASvBC,WAAW,CAACC,MAAD,EAA8B;IAAA;IAAA;IACrC,KAAKJ,IAAL,GAAY,IAAZ;IAEA,MAAMK,KAAK,GAAGC,OAAO,CAACC,GAAR,CAAYC,KAAZ,KAAsB,MAApC,CAHqC,CAKrC;;IACA,IAAIP,KAAK,GAAGJ,aAAa,CAACI,KAA1B;;IACA,IAAII,KAAK,IAAID,MAAM,CAACH,KAApB,EAA2B;MACvBA,KAAK,GAAGG,MAAM,CAACH,KAAf;IACH;;IAED,KAAKQ,KAAL,GAAa;MACTX,IAAI,EAAEM,MAAM,CAACN,IAAP,IAAeD,aAAa,CAACC,IAD1B;MAETC,OAAO,EAAEK,MAAM,CAACL,OAAP,IAAkBF,aAAa,CAACE,OAFhC;MAGTC,IAAI,EAAEI,MAAM,CAACJ,IAAP,IAAeH,aAAa,CAACG,IAH1B;MAITC,KAAK,EAAEA;IAJE,CAAb;EAMH;;AA1BsB;;;;AA6BpB,MAAMS,gBAAN,SAA+BR,aAA/B,CAA6C;EAChDC,WAAW,CAACJ,OAAD,EAAkB;IACzB,MAAM;MACFD,IAAI,EAAE,WADJ;MAEFC;IAFE,CAAN;EAIH;;AAN+C;;;;AAS7C,MAAMY,iBAAN,CAAwB;EAU3BR,WAAW,CAACC,MAAD,EAA8B;IAAA;IAAA;IAAA;IACrC,KAAKQ,IAAL,GAAY,IAAZ;IACA,KAAKZ,IAAL,GAAY,IAAZ;IAEA,MAAMK,KAAK,GAAGC,OAAO,CAACC,GAAR,CAAYC,KAAZ,KAAsB,MAApC,CAJqC,CAMrC;;IACA,IAAIP,KAAK,GAAGJ,aAAa,CAACI,KAA1B;;IACA,IAAII,KAAK,IAAID,MAAM,CAACH,KAApB,EAA2B;MACvBA,KAAK,GAAGG,MAAM,CAACH,KAAf;IACH;;IAED,KAAKQ,KAAL,GAAa;MACTX,IAAI,EAAEM,MAAM,CAACN,IAAP,IAAeD,aAAa,CAACC,IAD1B;MAETC,OAAO,EAAEK,MAAM,CAACL,OAAP,IAAkBF,aAAa,CAACE,OAFhC;MAGTC,IAAI,EAAEI,MAAM,CAACJ,IAAP,IAAeH,aAAa,CAACG,IAH1B;MAITC,KAAK,EAAEA;IAJE,CAAb;EAMH;;AA5B0B;;;;AA+BxB,MAAMY,QAAN,CAAwB;EAI3BV,WAAW,CAACH,IAAD,EAAU;IAAA;IAAA;IACjB,KAAKA,IAAL,GAAYA,IAAZ;IACA,KAAKS,KAAL,GAAa,IAAb;EACH;;AAP0B;;;;AAUxB,MAAMK,YAAN,CAAyB;EAK5BX,WAAW,CAACH,IAAD,EAAiBY,IAAjB,EAA2B;IAAA;IAAA;IAAA;IAClC,KAAKZ,IAAL,GAAYe,KAAK,CAACC,OAAN,CAAchB,IAAd,IAAsBA,IAAtB,GAA6B,EAAzC;IACA,KAAKY,IAAL,GAAYA,IAAI,IAAK,EAArB;IACA,KAAKH,KAAL,GAAa,IAAb;EACH;;AAT2B"}
package/types.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
2
2
  import { Plugin } from "@webiny/plugins/types";
3
- import { ContextInterface } from "@webiny/handler/types";
3
+ import { Context } from "@webiny/api/types";
4
+ import { RouteMethodPath } from "@webiny/handler/types";
4
5
  export interface GraphQLScalarPlugin extends Plugin {
5
6
  type: "graphql-scalar";
6
7
  scalar: GraphQLScalarType;
7
8
  }
8
9
  export interface HandlerGraphQLOptions {
10
+ path?: RouteMethodPath;
9
11
  debug?: boolean | string;
10
12
  }
11
- export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = ContextInterface> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
13
+ export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = Context> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
12
14
  export declare type Types = string | (() => string | Promise<string>);
13
15
  export interface GraphQLSchemaPluginTypeArgs {
14
16
  context?: any;
@@ -22,7 +24,7 @@ export interface GraphQLSchemaDefinition<TContext> {
22
24
  typeDefs: Types;
23
25
  resolvers?: Resolvers<TContext>;
24
26
  }
25
- export interface GraphQLSchemaPlugin<TContext extends ContextInterface = ContextInterface> extends Plugin {
27
+ export interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {
26
28
  type: "graphql-schema";
27
29
  schema: GraphQLSchemaDefinition<TContext>;
28
30
  }
@@ -31,7 +33,7 @@ export interface GraphQLRequestBody {
31
33
  variables: Record<string, any>;
32
34
  operationName: string;
33
35
  }
34
- export interface GraphQLBeforeQueryPlugin<TContext extends ContextInterface = ContextInterface> extends Plugin {
36
+ export interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {
35
37
  type: "graphql-before-query";
36
38
  apply(params: {
37
39
  body: GraphQLRequestBody;
@@ -39,7 +41,7 @@ export interface GraphQLBeforeQueryPlugin<TContext extends ContextInterface = Co
39
41
  context: TContext;
40
42
  }): void;
41
43
  }
42
- export interface GraphQLAfterQueryPlugin<TContext extends ContextInterface = ContextInterface> extends Plugin {
44
+ export interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {
43
45
  type: "graphql-after-query";
44
46
  apply(params: {
45
47
  result: any;
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n// `GraphQLSchemaPlugin` types.\nexport type Types = string | (() => string | Promise<string>);\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> =\n | GraphQLScalarType\n | GraphQLFieldResolver<any, Record<string, any>, TContext>\n | { [property: string]: Resolvers<TContext> };\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":""}