Apollo Graphql Custom Scalar JSON - complains "TypeError: type.getFields is not a function" - json

I'm working on an apollo-express graphql server. I attempted to integrate the module 'graphql-type-json' but when I followed this description on how to integrate, I've tried many things but it seems that the type isn't being passed to the resolver correctly - but I've hit a wall in my debugging and could use a little help. Here is a summary of what I'm doing.
import { makeExecutableSchema } from 'graphql-tools';
const GraphQLJSON = require('graphql-type-json');
//Have also tried import GraphQLJSON from 'graphql-type-json';
const schema = `
scalar JSON
type Device {
deviceconfig: JSON
}
type Query {
foo: Foo
}
`;
const resolveFunctions = {
JSON: GraphQLJSON,
//JSON: {return GraphQLJSON} stops error but other issues come up...
Query: ...
};
const jsSchema = makeExecutableSchema({
typeDefs: schema,
resolvers: resolveFunctions,
resolverValidationOptions: {
requireResolversForNonScalar: false,
},
allowUndefinedInResolve: true,
printErrors: true,
});
Not sure if it's relevant but there are a few issues with my npm:
graphql-type-json#0.1.4
UNMET PEER DEPENDENCY graphql#0.8.2 invalid
├─┬ graphql-tools#0.4.2
│ ├── UNMET PEER DEPENDENCY graphql#^0.5.0 || ^0.6.0
npm ERR! peer dep missing: graphql#^0.6.1 || ^0.7.0, required by apollo-server#0.3.3
npm ERR! peer dep missing: graphql#^0.5.0, required by graphql-tools#0.4.2
npm ERR! extraneous: casual#1.5.8 /home/apollo/node_modules/casual
npm ERR! extraneous: mongoose#4.6.6 /home/apollo/node_modules/mongoose
npm ERR! extraneous: mysql-events#0.0.8 /home/apollo/node_modules/mysql-events
npm ERR! peer dep missing: graphql#^0.5.0 || ^0.6.0, required by express-widgetizer#0.5.11

I resolved custom scalar JSON like this in resolvers
JSON: {
__serialize(value) {
return GraphQLJSON.parseValue(value);
} }
And It worked fine for me. I think it will help you

Related

invalid json response body error, while deploying Next.js app to Vercel

App builds fine locally and works on local production server + development server.
The api used to fetch data is working fine.
Code which is producing the error
export const getStaticProps = async () => {
const resp = await fetch(
'https://cdn-api.co-vin.in/api/v2/admin/location/states',
{
headers: {
'User-Agent': '*',
}, //this is required by api provider
}
);
const data = await resp.json();
//console.log('states in getStaticProps : ', data);
return { props: { data: JSON.parse(JSON.stringify(data)) } };
};
const Ninjas = ({ data: { states } }) => {
console.log('Ninjas : ', states);
return (
<>
<Head>
<title> Listing</title>
</Head>
<div>
{states.map((ei) => (
<div key={ei.state_id}>
<a className={styles.single}>
<h3>{ei.state_name}</h3>
</a>
</div>
))}
</div>
</>
);
};
export default Ninjas;
Following is the vercel log.
20:17:40.644 Cloning github.com/user-name/co2-app (Branch: main, Commit: 8ab0e48)
20:17:41.349 Cloning completed: 704.592ms
20:17:41.374 Analyzing source code...
20:17:42.573 Installing build runtime...
20:17:45.235 Build runtime installed: 2.662s
20:17:48.104 Looking up build cache...
20:17:48.453 Build cache not found
20:17:49.697 Installing dependencies...
20:18:04.559 > ejs#2.7.4 postinstall /vercel/path0/node_modules/ejs
20:18:04.559 > node ./postinstall.js
20:18:05.113 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#2.3.2 (node_modules/fsevents):
20:18:05.113 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
20:18:05.116 added 600 packages from 352 contributors in 14.87s
20:18:05.426 64 packages are looking for funding
20:18:05.426 run `npm fund` for details
20:18:05.492 Detected Next.js version: 10.2.0
20:18:05.492 Running "npm run build"
20:18:05.756 > we2-cowax#0.1.0 build /vercel/path0
20:18:05.757 > next build
20:18:07.292 info - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
20:18:08.224 info - Checking validity of types...
20:18:08.244 Attention: Next.js now collects completely anonymous telemetry regarding usage.
20:18:08.245 This information is used to shape Next.js' roadmap and prioritize features.
20:18:08.245 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
20:18:08.245 https://nextjs.org/telemetry
20:18:08.326 info - Creating an optimized production build...
20:18:08.748 > [PWA] Compile client (static)
20:18:08.748 > [PWA] Auto register service worker with: /vercel/path0/node_modules/next-pwa/register.js
20:18:08.750 > [PWA] Service worker: /vercel/path0/public/service-worker.js
20:18:08.750 > [PWA] url: /service-worker.js
20:18:08.750 > [PWA] scope: /
20:18:08.860 > [PWA] Compile server
20:18:25.603 info - Compiled successfully
20:18:25.604 info - Collecting page data...
20:18:26.366 info - Generating static pages (0/3)
20:18:26.918 error : invalid json response body at https://cdn-api.co-vin.in/api/v2/admin/location/states reason: Unexpected token < in JSON at position 0
20:18:26.919 Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
20:18:26.919 Error: Error serializing props returned from `getStaticProps` in "/".
20:18:26.919 Reason: Props must be returned as a plain object from getStaticProps: `{ props: { ... } }`.
20:18:26.919 at isSerializableProps (/vercel/path0/node_modules/next/dist/lib/is-serializable-props.js:1:462)
20:18:26.919 at renderToHTML (/vercel/path0/node_modules/next/dist/next-server/server/render.js:30:1730)
20:18:26.919 at processTicksAndRejections (internal/process/task_queues.js:93:5)
20:18:26.919 at async /vercel/path0/node_modules/next/dist/export/worker.js:26:6
20:18:26.919 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
20:18:26.920 info - Generating static pages (3/3)
20:18:26.921 > Build error occurred
20:18:26.926 Error: Export encountered errors on following paths:
20:18:26.926 /
20:18:26.926 at /vercel/path0/node_modules/next/dist/export/index.js:31:1106
20:18:26.926 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
20:18:26.927 at async /vercel/path0/node_modules/next/dist/build/index.js:43:49
20:18:26.927 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
20:18:26.927 at async /vercel/path0/node_modules/next/dist/build/index.js:25:1475
20:18:26.927 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
20:18:26.954 npm ERR! code ELIFECYCLE
20:18:26.954 npm ERR! errno 1
20:18:26.958 npm ERR! co2-app#0.1.0 build: `next build`
20:18:26.958 npm ERR! Exit status 1
20:18:26.958 npm ERR!
20:18:26.959 npm ERR! Failed at the we2-cowax#0.1.0 build script.
20:18:26.959 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
20:18:26.968 npm ERR! A complete log of this run can be found in:
20:18:26.968 npm ERR! /vercel/.npm/_logs/2021-05-17T14_48_26_959Z-debug.log
20:18:26.982 Error: Command "npm run build" exited with 1
I am using next-pwa for PWA functionality and hence custom webpack version
Have delete the app at Vercel and re-deploy, even removed the cache build but still can't resolve the error
Problem
The API is returning a 403 forbidden error:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD>
<BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a
configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: BqNxi8x1nTA3YKM_N3JSCyjGVDYnMUDNFvS_HgJGB8glTFr1uVh6Ug==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY>
</HTML>
which is not then being handled correctly by your getStaticProps function (in this case, an invalid response can't be turned into JSON; also, your User-Agent is not valid):
export const getStaticProps = async () => {
const resp = await fetch(
'https://cdn-api.co-vin.in/api/v2/admin/location/states',
{
headers: {
'User-Agent': '*',
}, //this is required by api provider
}
);
// this throws an error because you can't turn
// the invalid server response into JSON
const data = await resp.json();
return { props: { data: JSON.parse(JSON.stringify(data)) } };
};
which is also not being handled correctly by your Ninjas component -- states would be undefined because the server doesn't respond with valid data and you can't map an undefined variable. Instead you should check that states is a non-empty Array before mapping over it by either using lodash's isEmpty: !isEmpty(states) && states.map(...) or by checking that it's defined and has length: Array.isArray(states) && states.length > 0 && states.map(...).
Solution
import Head from "next/head";
import isEmpty from "lodash.isempty";
export const getStaticProps = async () => {
let data = [];
let error = "";
try {
const res = await fetch(
"https://cdn-api.co-vin.in/api/v2/admin/location/states",
{
method: "GET",
headers: {
// update with your user-agent
"User-Agent":
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36",
Accept: "application/json; charset=UTF-8",
},
}
);
if (res.status !== 200)
throw String(`Invalid server response: ${res.status} ${res.statusText}`);
data = await res.json();
if (isEmpty(data)) throw String("No data was found!");
data = JSON.parse(JSON.stringify(data));
} catch (e) {
error = e.toString();
}
return {
props: {
data,
error,
},
};
};
const Ninjas = ({ data, error }) => (
<>
<Head>
<title> Listing</title>
</Head>
<div>
{error && <p style={{ color: "red" }}>{error}</p>}
{!isEmpty(data) && !isEmpty(data.states) &&
data.states.map((ei) => (
<div key={ei.state_id}>
<a className={styles.single}>
<h3>{ei.state_name}</h3>
</a>
</div>
))}
</div>
</>
);
export default Ninjas;

Angular 6 ERROR in Couldn't resolve original symbol for ./src/util/decorators from .../node_modules/#angular/core/core.d.ts

I try to run the following to build my project for production and receive the error as stated in the subject:
ng build --prod
When I look in the core.d.ts file, it cannot find the following:
"./src/change_detection/differs/default_iterable_differ";
"./src/profile/profile";
"./src/util/decorators";
The following is the entire file:
/**
* Generated bundle index. Do not edit.
*/
export * from "./index";
export {
APPLICATION_MODULE_PROVIDERS as ɵangular_packages_core_core_l,
_iterableDiffersFactory as ɵangular_packages_core_core_i,
_keyValueDiffersFactory as ɵangular_packages_core_core_j,
_localeFactory as ɵangular_packages_core_core_k
} from "./src/application_module";
export {
_appIdRandomProviderFactory as ɵangular_packages_core_core_f
} from "./src/application_tokens";
export {
DefaultIterableDifferFactory as ɵangular_packages_core_core_g
} from "./src/change_detection/differs/default_iterable_differ";
export {
DefaultKeyValueDifferFactory as ɵangular_packages_core_core_h
} from "./src/change_detection/differs/default_keyvalue_differ";
export {
ReflectiveInjector_ as ɵangular_packages_core_core_c
} from "./src/di/reflective_injector";
export {
ReflectiveDependency as ɵangular_packages_core_core_d,
resolveReflectiveProviders as ɵangular_packages_core_core_e
} from "./src/di/reflective_provider";
export {
wtfEnabled as ɵangular_packages_core_core_m
} from "./src/profile/profile";
export {
createScope as ɵangular_packages_core_core_o,
detectWTF as ɵangular_packages_core_core_n,
endTimeRange as ɵangular_packages_core_core_r,
leave as ɵangular_packages_core_core_p,
startTimeRange as ɵangular_packages_core_core_q
} from "./src/profile/wtf_impl";
export {
getOrCreateChangeDetectorRef as ɵangular_packages_core_core_v,
getOrCreateContainerRef as ɵangular_packages_core_core_y,
getOrCreateElementRef as ɵangular_packages_core_core_x,
getOrCreateInjectable as ɵangular_packages_core_core_w,
getOrCreateNodeInjector as ɵangular_packages_core_core_u,
getOrCreateTemplateRef as ɵangular_packages_core_core_z
} from "./src/render3/di";
export {
bindingUpdated as ɵangular_packages_core_core_ba
} from "./src/render3/instructions";
export {
loadInternal as ɵangular_packages_core_core_bb
} from "./src/render3/util";
export {
makeParamDecorator as ɵangular_packages_core_core_a,
makePropDecorator as ɵangular_packages_core_core_b
} from "./src/util/decorators";
export { _def as ɵangular_packages_core_core_s } from "./src/view/provider";
export {
DebugContext as ɵangular_packages_core_core_t
} from "./src/view/types";
Do I run npm i decorators? If I run the following:
ng serve --disable-host-check
Correction to original post - now the project does not run at all. What happened? I have been testing this thing for over a month and, now that I am ready to go live, it just does not work at all after trying to create a dist directory. WTF?
The following is what I am seeing in the console:
TypeError: Class constructor Subject cannot be invoked without 'new'
at new EventEmitter (core.umd.js:3597)
at new NgZone (core.umd.js:3745)
at getNgZone (core.umd.js:4473)
at PlatformRef.push../node_modules/#angular/core/bundles/core.umd.js.PlatformRef.bootstrapModuleFactory (core.umd.js:4369)
at core.umd.js:4415
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
at zone.js:872
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
When I run ng build I am seeing the following:
ng build --prod
Date: 2019-02-02T23:59:21.603Z
Hash: 51184dcdbc91f92a675d
Time: 3998ms
chunk {0} runtime.6afe30102d8fe7337431.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.42d170ae18051bd9f923.css (styles) 177 kB [initial] [rendered]
chunk {2} polyfills.03b06938f23b8f1cb153.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} main.541dbdbf0b123b4c3be8.js (main) 128 bytes [initial] [rendered]
ERROR in Couldn't resolve original symbol for ./src/util/decorators from /Applications/MAMP/htdocs/oshop/node_modules/#angular/core/core.d.ts
BTW, now in app.module.ts, it cannot find module for HttpClientModule or HTTP_INTERCEPTORS
Cannot find module '#angular/common/http'
When I try to re-install #angular/common:
sudo npm i -g #angular/common^6.1.10
npm ERR! code ENOLOCAL
npm ERR! Could not install from "#angular/common^6.1.10" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/tam3/.npm/_logs/2019-02-03T02_29_27_361Z-debug.log
But it is in the package.json:
"devDependencies": {
"#angular-devkit/build-angular": "~0.7.0",
"#angular/cli": "~6.1.0",
"#angular/common": "~6.1.10",
"#angular/compiler-cli": "^6.1.0",
"#angular/core": "^6.1.10",
WTF, I followed a post that suggested all I had to do was to trash the node_modules directory, followed by npm install and it would reinstall everything. What can I do? I literally was ready to go live today
Thanks in advance
I was able to solve this issue, by solving various other issues, that I pointed out in another post that I made on stackoverflow
First, I had to make sure that the npm(s) were no longer being installed in .npm-global, which I had done to get around no longer typing sudo before every/any install, but that came at a price, which I outline in the aforementioned post.
Second, I followed a couple of other posts on stackoverflow that instructed me to change my dependencies in the package.json file to the following:
"rxjs": "6.0.0",
"typescript": "^2.7.2",
Followed by deleting the node_modules directory, then do an npm install, but this only worked because my npm installs were no longer being installed in ~/.npm-global.
Also, as I stated in the other post, the build is still not working, but that is because there are so many other errors that I have to resolve going forward, but at least this issue is out of way and my system is back to where it was before this error popped up.
These are some of the errors moving forward that I am referring to:
Property 'value' does not exist on type 'HTMLElement'
Property 'shoppingCart' does not exist on type {}

Gcloud background functions with depedencies fail to deploy

Below is a basic example of gcloud background function with a dependency in it. On using uuid package it throws up an error although package.json has uuid
On deploying following erros is received.
gcloud beta functions deploy helloPubSub --trigger-resource my-topic --trigger-event google.pubsub.topic.publish
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'uuid'
index.js
const uuid = require('uuid');
exports.helloPubSub = (event, callback) => {
const pubsubMessage = event.data;
const eventName = pubsubMessage.data ? Buffer.from(pubsubMessage.data, 'base64').toString() : 'World';
console.log(eventName,uuid.v4());
callback();
};
package.json
"dependencies": {
"uuid": "^3.2.1"
},
There was an issue in my .gcloudignore
Below change did make it work!
From
node_modules/
to
node_modules

npm install is not installing + grunt-contrib.copy not found

I have two questions. I am completing a project from the book "Learning to Program", and am a little confused as to why npm is not installing, and why I am receiving another error message. I'm using Windows, I have installed node.js (v0.12.2) and have attempted to install grunt: npm install -g grunt-cli
Question 1 - When I try to install npm, it does not list all of the dependencies defined in package.json.
The following shows when I try to install npm in my main directory:
C:\Users\Me\My Documents\kittenbook\npm install
npm WARN package.json kittenbook#0.0.1 No description
npm WARN package.json kittenbook#0.0.1 No repository field
npm WARN package.json kittenbook#0.0.1 No README data
From what I see, it's supposed to display a bunch of lines after those three warnings, such as:
npm http GET https://registry.npmjs.org/grunt-contrib-concat
npm http GET https://registry.npmjs.org/grunt
npm http GET https://registry.npmjs.org/grunt-contrib-copy
and so on.
Question 2:
This is probably because installing npm is not working correctly, but when I try to run "grunt jshint" it gives me this error:
>> Local Npm module "grunt-contrib-.copy" not found. Is it installed?
Running "jshint:files" (jshint) task
>> 2 files lint free
Done, without errors.
Sorry for this very unorganized question, but I am very new to programming and I am very confused as to where the problem is.
Here is some more information.
Gruntfile.js
module.exports = function(grunt) {
// Project configuration
grunt.initConfig({
concat: {
release: {
src: ['js/values.js', 'js/prompt.js'],
dest: 'release/main.js'
}
},
copy: {
release: {
src: 'manifest.json',
dest: 'release/manifest.json'
}
},
jshint: {
files: ['js/values.js', 'js/prompt.js']
}
});
// Load Grunt plugins
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib.copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Register Tasks
grunt.registerTask('default', ['jshint', 'concat', 'copy']);
};
package.json
{
"name": "kittenbook",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-copy": "~0.5.0"
}
}
If you need other information I will gladly get it to you. Thank you all so much for your help.
grunt-contrib.copy should be grunt-contrib-copy (use dash, not period)

Why "gulp-jest" is failing with: "Please run node with the --harmony flag!"?

I get the following error when running gulp test:
Error: Please run node with the --harmony flag!
Here is my gulp task:
var jest = require('gulp-jest');
gulp.task('test', function() {
return gulp.src('src/**/__tests__').pipe(jest({
rootDir: 'src',
scriptPreprocessor: '../node_modules/6to5-jest',
unmockedModulePathPatterns: [ 'react' ]
}));
});
To reproduce: https://github.com/SEEK-Jobs/react-playground
Note that npm test works properly (test is failing as expected), but gulp test fails with the error above. Both npm test and gulp test have the same config object:
{
rootDir: 'src',
scriptPreprocessor: '../node_modules/6to5-jest',
unmockedModulePathPatterns: [ 'react' ]
}
What am I doing wrong?
As far as I can tell the error is thrown from jest-cli.
The reason you don't get it with npm test is that you probably configured npm to run the jest bin script directly, which uses harmonize to programmatically set the --harmony flag.
You can fix by installing harmonize and putting require('harmonize')() in your gulpfile.
It was a bug in gulp-eslint, and it is fixed now in version 0.3.0.