import * doesn't load the object in es6 - babeljs

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

Related

Module "punycode" has been externalized for browser compatability

I am trying to use the '#ensdomains/eth-ens-namehash' package to hash an input.
I am using it in combination with 'pinia'.
I call on this method in Nuxt3.
This is the code:
import { defineStore } from "pinia"
import namehash from "#ensdomains/eth-ens-namehash"
import { Buffer } from 'buffer'
export const exampleMethod = defineStore('example', {
state: () => {
return{
hash: String
}
},
actions: {
method(input) {
globalThis.Buffer = Buffer
this.hash = namehash.hash(input).toString()
}
}
}
When trying to call 'method' I get the following error:
Uncaught (in promise) Error: Module "punycode" has been externalized
for browser compatibility. Cannot access "punycode.ucs2" in client
code.

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.

How to make serializer get called

I'm using ember cli
ember 1.12.0
ember data 1.0.0-beta.18
router.js:
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('datasource');
});
//export default Router;
export default Router;
routes/datasource.js:
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
// the model is an Array of all of the posts
// fetched from this url
return Ember.$.ajax('/datasource/');
//return [{'datasource': '1'}, {'datasource': '2'}];
}
});
adapters/application.js:
import DS from 'ember-data';
export default DS.Adapter.extend({
// ...your code here
});
models/datasource.js:
import DS from 'ember-data';
export default DS.Model.extend({
dsn: DS.attr()
});
serializers/datasource.js:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
extractArray: function(store, type, payload) {
var datasources = payload._items;
payload = {datasources: datasources};
return this._super(store, type, payload);
}
});
Ie my api returns the list of items inside the key _items.
But it looks like the serializer is never executed,
What should I do to make the serializer take effect?
This is the error -
Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed '{_items: [object Object],[object Object], _links: [object Object], _meta: [object Object]}' (wrapped in (generated datasource controller))Ember.default.assert # ember.debug.js:4854exports.default.CollectionView.default.extend._assertArrayLike # ember.debug.js:38837(anonymous function) # ember.debug.js:37836ContainerView.default.extend.init # ember.debug.js:37804superWrapper # ember.debug.js:17426superFunction # ember.debug.js:13805mixin.Mixin.create.init # ember.debug.js:38898superWrapper # ember.debug.js:17426superFunction # ember.debug.js:13805exports.default.CollectionView.default.extend.init # ember.debug.js:38832superWrapper # ember.debug.js:17426Class # ember.debug.js:30649ClassMixinProps.create # ember.debug.js:31071mixin.Mixin.create.createChildView # ember.debug.js:35755merge.default.appendChild # ember.debug.js:39847mixin.Mixin.create.appendChild # ember.debug.js:35697appendTemplatedView # ember.debug.js:8051viewHelper # ember.debug.js:7559collectionHelper # ember.debug.js:6410eachHelper # ember.debug.js:6598block # ember.debug.js:7807render # datasource.js:89renderHTMLBarsTemplate # ember.debug.js:8491renderView # ember.debug.js:8463renderView # ember.debug.js:35400mixin.Mixin.create.render # ember.debug.js:35423EmberRenderer_createElement # ember.debug.js:37468Renderer_renderTree # ember.debug.js:9140scheduledRenderTree # ember.debug.js:9216Queue.invoke # ember.debug.js:878Queue.flush # ember.debug.js:943DeferredActionQueues.flush # ember.debug.js:748Backburner.end # ember.debug.js:173(anonymous function) # ember.debug.js:576
In the model hook of your route you are doing a ajax call instead of calling the store to find records. With the ajax call you are bypassing your store and so the serializer will never be called to serialize the payload returned from your server.
In order to pass the payload to the store you can do:
// route
model: function() {
var store = this.store;
return Ember.$.ajax('/datasource/').then(function(payload) {
store.pushPayload('datasource', payload);
});
}
Alternatively you can call the store to do the call to your back-end so you don't have to do a ajax call yourself (not sure if it was your intention to do a custom call for some reason):
// route
model: function() {
return this.store.find('datasource');
}

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