I am storying names in my database from foreign countries which mean a few of the characters are not easily stored in my db for some reason:
Example name that is not stored correctly:
Moretó Font
It is a postgres DB with a graphQL layer on to to get the data out.
DB Info:
psqlDB| TF8 | en_GB.UTF-8 | en_GB.UTF-8 |
I have <meta charSet="utf-8"/> in the page
I'm using:
postgres v12
node.js v14.15.4
nextjs v10
graphql v15.4
postgraphile: v4.5.5
postgraphile generates my schemas and resolves for me so a typical write to my DB looks like within my nextjs application (javascript):
mutation createArtist(
$firstname: String!
$surname: String!
) {
createArtist(
input: {
artist: {
firstname: $firstname
surname: $surname
}
}
) {
clientMutationId
}
}
create({ variables: { firstname: 'jamie', surname: 'hutber'} })
I wonder if I need to remove all these chars while storing them in the DB?
Related
I am trying to query by passing in the name field but I get two different errors.
"Validation error of type MissingFieldArgument:
Missing field argument id # 'getBlog'"
"Validation error of type UnknownArgument:
Unknown field argument name # 'getBlog'"
I was able to successfully query it with the id field. Im new to graphql and im using this on my app that also uses aws amplify and aws appsync.
schema.graphql
type Blog #model {
id: ID!
name: String!
posts: [Post] #connection(keyName: "byBlog", fields: ["id"])
}
queries.ts
// this is an auto generated file. This will be overwritten
export const getBlog = /* GraphQL */ `
query GetBlog($name: String!) { //changed from ($id: ID!)
getBlog(name: $name) { //changed from (id: $id)
id
name
posts {
items {
id
title
blogID
createdAt
updatedAt
}
nextToken
}
createdAt
updatedAt
}
}
`;
app.tsx
const getRecord = async () => {
const result = await API.graphql(graphqlOperation(getBlog, {name: "testing"}))
console.log(result)
}
I also tried pushing it to aws amplify push but it detected no changes. I didnt expect it to as i didnt change anything in the schema, only the queries. thanks in advance
If you look at your GraphQL schema you should see the definition for the GetBlog query. It likely looks like:
query {
GetBlog(id: ID!): Blog
}
That particular query can only be queried by id. Assuming you have control of the server you should also be able to define a GetBlogByName query:
query {
GetBlogByName(name: String): Blog
}
But then it will be up to you to ensure that name is unique or deal with potentially >1 response.
I'm trying to connect to multiple databases from single connection using typeORM in javascript. There's a way doing it using typescript
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
#Entity({ database: "secondDB" })
export class User {
#PrimaryGeneratedColumn()
id: number;
#Column()
firstName: string;
#Column()
lastName: string;
}
I tried to replicate this in javascript like this:
const { EntitySchema } = require("typeorm");
const userSchema = {
name: "User",
database: "secondDB",
columns: {
id: {
primary: true,
type: "int",
generated: true
},
firstName: {
type: "text"
},
lastName: {
type: "text"
},
}
module.exports = new EntitySchema(userSchema);
This doesn't seem to switch databases, Is there an equivalent way of doing this in javascript. I'm connecting to a postgresDB
It's been a while since I worked with type-orm, but I know that a single connection with multiple databases at the time was only supported for MySQL and MsSQL databases.
In this document: https://orkhan.gitbook.io/typeorm/docs/multiple-connections.
It states that "Using multiple databases in a single connection" "this feature is supported only in mysql and mssql databases".
link to relevant github issue
Am new to Graphql and actually following a tutorial. I am building a project in React Native and using AWS Amplify and Graphql for my backend. I needed a little change from the tutorial am following, I want users to be able to view user profile of other users in a their contact list just Instagram or Facebook.
In my schema.graphql I have the following code:
type User #model {
id: ID!
name: String!
imageUri: String
username: String!
email: String!
}
But I don't know the next code to write for user profile and the relationships for users to view other user user profiles.
I have been able to list contacts with the following code:
useEffect(() => {
const fetchUsers = async () => {
try {
const usersData = await API.graphql(
graphqlOperation(
listUsers
)
)
setUsers(usersData.data.listUsers.items);
} catch (e) {
console.log(e);
}
}
fetchUsers();
}, [])
Please I need guide on how to achieve viewing user profile when user is clicked on the contact list.
you have to add "auth" rule to your model
type User #model
#auth(
rules: [
#this is for logged-in user. cognito user is default for provider
# In order to prevent private users from creating, another rule must be set for creating
{ allow: private, operations: [read] }
# default provider is cognito
{ allow: private, provider: iam, operations: [read, create, update, delete] }
# Only Owner can update its own data
{ allow: owner, ownerField: "username", operations: [update] }
]
) {
id: ID!
name: String!
imageUri: String
username: String!
email: String!
}
In the above code, I defined two auth rules. One is for Cognito user, he can only read, another one for the "iam" user who has more privileges.
I've been fighting with trying to get Mongoose to return data from my local MongoDB instance; I can run the same command in the MongoDB shell and I get results back. I have found a post on stackoverflow that talks about the exact problem I'm having here; I've followed the answers on this post but I still can't seem to get it working. I created a simple project to try and get something simple working and here's the code.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
userId: Number,
email: String,
password: String,
firstName: String,
lastName: String,
addresses: [
{
addressTypeId: Number,
address: String,
address2: String,
city: String,
state: String,
zipCode: String
}
],
website: String,
isEmailConfirmed: { type: Boolean, default: false },
isActive: { type: Boolean, default: true },
isLocked: { type: Boolean, default: false },
roles: [{ roleName: String }],
claims: [{ claimName: String, claimValue: String }]
});
var db = mongoose.connect('mongodb://127.0.0.1:27017/personalweb');
var userModel = mongoose.model('user', userSchema);
userModel.findOne({ email: 'test#test.com' }, function (error, user) {
console.log("Error: " + error);
console.log("User: " + user);
});
And here is the response of the 2 console.log statements:
Error: null
User: null
When the connect method is called I see the connection being made to my Mongo instance but when the findOne command is issued nothing appears to happen. If I run the same command through the MongoDB shell I get the user record returned to me. Is there anything I'm doing wrong?
Thanks in advance.
Mongoose pluralizes the name of the model as it considers this good practice for a "collection" of things to be a pluralized name. This means that what you are currently looking for in code it a collection called "users" and not "user" as you might expect.
You can override this default behavior by specifying the specific name for the collection you want in the model definition:
var userModel = mongoose.model('user', userSchema, 'user');
The third argument there is the collection name to be used rather than what will be determined based on the model name.
I know 7 years pass, however I'm starting to develop in node JS with MongoDB using mongoose, so searching for solution to the same problem, result = null.
After read this post and all the answers, I release that I totally forget to include the DB name in the string of the connection, 'mongodb://localhost:27017/DB name' so that solved my case. I guessed this can be help other clueless like me! :)
I am trying to use user-defined types in Cassandra with nodejs.
Following the documentation, I successfully manage to do it in cqlsh (https://www.datastax.com/documentation/cql/3.1/cql/cql_using/cqlUseUDT.html). I manage to insert items in cqlsh but not ussing the cassandra-driver module.
I understand they are some intricacies do to the use of javascript (http://www.datastax.com/documentation/developer/nodejs-driver/1.0/nodejs-driver/reference/nodejs2Cql3Datatypes.html) and I have tried the different options offered but I couldnt not get it to work.
Here are my trials and their resulting error message:
var insertQuery = 'INSERT INTO mykeyspace.users (id, name) VALUES (?, ?)'
client.execute(insertQuery, ['62c36092-82a1-3a00-93r1-46196ee77204', { firstname: 'paul', lastname: 'jacques'}], {hints: ['uuid', 'map<text, text>']}, function(err) { console.log(err);})
{ name: 'ResponseError',
message: 'Not enough bytes to read 0th field java.nio.HeapByteBuffer[pos=0 lim=9 cap=9]',
info: 'Represents an error message from the server',
code: 8704,
query: 'INSERT INTO mykeyspace.users (id, name) VALUES (?, ?)' }
client.execute(insertQuery, ['62c36092-82a1-3a00-93r1-46196ee77204', { firstname: 'paul', lastname: 'jacques'}], { prepare: true }, function(err) { console.log(err);})
{ [TypeError: Not a valid blob, expected Buffer obtained { firstname: 'paul', lastname: 'jacques' }]
query: 'INSERT INTO mykeyspace.users (id, name) VALUES (?, ?)' }
Then what is the correct syntax to get it to work?
NB. I am using cassandra 2.1.1
The DataStax Node.js driver does not support User defined types yet, so the driver won't be able to serialize the data accordingly.
You can use json notation in CQL to access the individual fields. For example, queries like the following will work:
SELECT addr.street, addr.city FROM location WHERE id=?;
or
UPDATE SET addr['street'] = ?, addr['city'] = ? WHERE id = ?