Coffeescript property Error: Parse error on line 5: Unexpected '{ - coffeescript

I have this code in Coffeescript
window.App = new Backbone.Marionette.Application
Models: {}
Collections: {}
Views: {}
Views.Layouts: {}
Routers: {}
And I'm trying to get this javascript code
window.App = new Backbone.Marionette.Application({
Models: {},
Collections: {},
Views: {},
Views.Layouts: {},
Routers: {}
});
I get this error: Error: Parse error on line 5: Unexpected '{

I think this is what you're trying to do:
window.App = new Backbone.Marionette.Application
Models: {}
Collections: {}
Views:
Layouts: {}
Routers: {}

Related

importing schema from file causes ReferenceError: Cannot access 'MySchema' before initialization

I have a schema that I export from a file
// Vendor.ts
export { ShortVendorSchema };
const ShortVendorSchema = new Schema<TShortVendor>({
defaultVendor: Boolean,
companyName: String,
vendorId: { type: Schema.Types.ObjectId, ref: 'Vendor' },
});
and import it to another schema
// Order.ts
import { ShortVendorSchema } from './Vendor';
const OrderSchema = new Schema<TOrderSchema>(
{
status: {
type: String,
enum: Object.keys(ORDER_STATUS),
default: 'NEW',
},
vendor: ShortVendorSchema,
},
{ timestamps: true }
);
Whenever I'm trying to access Order model I get error error - ReferenceError: Cannot access 'ShortVendorSchema' before initialization
I have an idea why it happens, something about api routes living in isolation, but I don't know how to solve it without duplicating ShortVendorSchema in all files where it's used.
upd: moved all model exports into a single file, now I'm getting error error - TypeError: Cannot read properties of undefined (reading 'ShortVendorSchema')
Any ideas?
The error occurs because of circular dependency.
I was importing ShortVendorSchema to Order.ts file and OrderSchema to Vendor.ts file.
The solution is to move ShortVendorSchema to a separate file that doesn't have any imports.

Unexpected <EOF> while using graphql

Getting EOF error every time at same line, changed code many times and even degraded to previous versions of graphql but no positive results.
My code is:
const graphql = require('graphql')
const _ = require('lodash')
const {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLSchema
} = graphql
const users = [
{id: '1', firstName: 'Ansh', age: 20},
{id: '2', firstName: 'Ram', age: 21},
{id: '3', firstName: 'Sham', age: 20}
]
const UserType = new GraphQLObjectType({
name: 'User',
fields: {
id: {type: GraphQLString},
firstName: {type: GraphQLString},
age: {type: GraphQLInt}
}
})
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: UserType,
args: {id: {type: GraphQLString}},
resolve(parentValue, args) {
return _.find(users, {id: args.id})
}
}
}
})
module.exports = new GraphQLSchema({
query: RootQuery
})
Error is:
{
"errors": [
{
"message": "Syntax Error GraphQL request (30:1) Unexpected <EOF>\n\n29: \n30: \n ^\n",
"locations": [
{
"line": 30,
"column": 1
}
]
}
]
}
The issue is because the query you're passing might be empty.
For example:
curl -X POST http://localhost:4000/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ user { id } }"}'
works fine.
But if you make something like:
curl -X POST http://localhost:4000/graphql \
-H "Content-Type: application/json" \
-d '{"query": ""}'
You'll get unexpected < EOF >
Also, check GraphQL end of line issue.
I had comments in the schema.graphql file:
"""
Some comments
"""
I removed the comments and the Unexpected <EOF> error went away.
It's because there's no actual query so you get unexpected EOF (End of File).
Guessing that you're using GraphiQL (because your EOF message says line 30); you need to add a query on the left-hand panel of GraphiQL in the browser. Something which conforms to your RootQuery like:
{
user(id: "1") {
id,
firstName,
age
}
}
I got this error while trying to stitch my schema
the reason for this error was that I delcared a type but didn't implemet it, had empty body, for example:
type User {
}
implementing the type fixed it
It looks like if we are doing the schema-first approach, but we do not have any .graphql files in your project/empty. I added this and the error went away:
src/example.graphql
type Query {
hello: String
}
The "GraphQLError: Syntax Error: Unexpected " error is coming from the graphql package. It looks like #nestjs/graphql is assuming that there will always be at least one .graphql file, so this is probably a bug to try and parse an empty schema vs display a more developer-friendly message or ignore it.
In most cases passing an empty query is caused to this error.
To avoid this try this in your graphiql
query {
user {
fields you need to retrieve
}
}
This is because your graphql.gql looks like this:
# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------
directive #key(fields: String!) on OBJECT | INTERFACE
directive #extends on OBJECT | INTERFACE
directive #external on OBJECT | FIELD_DEFINITION
directive #requires(fields: String!) on FIELD_DEFINITION
directive #provides(fields: String!) on FIELD_DEFINITION
One thing you can do is create a dummy resolver.
// src/graphql/resolvers/user.resolver.ts
import { Resolver, Query } from '#nestjs/graphql';
import { User } from 'models/User.model';
#Resolver(() => User)
export class UserResolver {
#Query(() => User)
async ids() {
return [];
}
}
and create a graphql model:
// src/graphql/models
import { Field, ObjectType } from '#nestjs/graphql';
#ObjectType()
export class User {
#Field()
createdAt: Date;
}
And make sure that resolver is imported by a module and the module is added to App.module
This should fix it!
In my case on the frontend side (Angular), since I just wanted to observe something, I have this code:
I got this error:
Error: Unexpected <EOF>.
and I made it comment-line and the error was gone
How to fix it: Go to node_mudules > graphql > syntaxError.js and delete all comments from this file and the error should be gone.

Retrieve docs from MongoDB using Array

I have a route:
router.get('/:bar', (req, res) => {
Style.distinct('id', {'foo': req.params.bar })
.then(ids =>
// [00001, 00002, 00003, 00004, ... 99999]]
// get Style
// get Config
// etc..
});
});
In distinct then function, I would like to replace id 00001 with it's object & configuration (to do it, I have to query the Schema):
Style.find({'id', id})
Config.find({'id', id})
I'm stuck in callback hell.
I am trying to achieve the following output:
{
00001 : {
style: {}
config: {}
},
00002 : {
style: {}
config: {}
},
00003 : {
style: {}
config: {}
}
}
However, I am unsure how to return the response of two concurrent API calls in an object, and return an array of objects when complete.

import * doesn't load the object in es6

i18n directory with index.js and the localization files: es.js, it.js and en.js.
index.js content:
export { default as es } from './es'
export { default as it } from './it'
export { default as en } from './en'
en.js content file (similar to es.js and it.js):
/*eslint-disable max-len,quotes*/
export default {
"about.h1": "This is the title from the about page",
...
}
I try to load localization messages:
import * as i18n from 'i18n'
...
const intlData = {
locale: 'en',
messages: i18n['en']
}
However messages variable is undefined.
When I checked the console log with:
window.console.log(i18n)
I get undefined:
Object {__esMOdule: true}
es:undefined
get es: function get()
it: undefined
get it: function get()
en: undefined
get en: function get()
__proto__: Object
Where I should get something like:
Object {__esMOdule: true}
es: Object
it: Object
en: Object
__proto__: Object

ExtJS: Rest Proxy Post Data Failure

Hy,
I've a Problem by sending data via ExtJs Rest Proxy. When I POST Data I get the Exception
in Chrome: Uncaught TypeError: Cannot read property 'clientIdProperty' of undefined
in Firefox: TypeError: clientRecords[0] is undefined
My Store
Ext.define('Test.store.Test', {
extend: 'Ext.data.Store',
requires: [
'Test.model.test',
'Ext.data.proxy.Rest',
'Ext.data.reader.Json'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'Test',
model: 'Test.model.test',
proxy: {
type: 'rest',
url: '/resources/php/test.php',
reader: {
type: 'json'
}
}
}, cfg)]);
}
My Model
Ext.define('Test.model.test', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: [
{
name: 'Test'
}
]
Is there a standard answer from Server?
I hope some one can Help me
Thx for Help
In your reader config, provide a 'root' property.
In ext 4.x it'll be like
reader: {
type: 'json',
root: 'root'
}
And in Ext 5.x, it'll be
reader: {
type: 'json',
rootProperty: 'root'
}
Here's what API doc says -
rootProperty : String The name of the property which contains the data
items corresponding to the Model(s) for which this Reader is
configured. For JSON reader it's a property name (or a dot-separated
list of property names if the root is nested). For XML reader it's a
CSS selector. For Array reader the root is not applicable since the
data is assumed to be a single-level array of arrays.
By default the natural root of the data will be used: the root JSON
array, the root XML element, or the array.
The data packet value for this property should be an empty array to
clear the data or show no data.
Defaults to: ''
For example, if the JSON response from the server is
{
"data": {
"Test": "TEST"
},
"someOtherField": "Some Value"
}
then, your rootProperty/ root will become -
rootProperty: 'data'
- Since data corresponds to your model