NOTE: the __typename Client below refers to a person (like a customer) - not client/server.
Getting the following error:
Cache data may be lost when replacing the clientServices field of a Client object.
To address this problem (which is not a bug in Apollo Client), define a custom merge function for the Client.clientServices field, so InMemoryCache can safely merge these objects:
existing: [{"__ref":"ClientService:46"}]
incoming: []
What's happening is that I've deleted a "child" record - so there's no data.
First time I get this returned. Note: there's info associated with field clientServices
{
"client": {
"id": "41",
"companyId": "3",
"firstName": "Lew",
"lastName": "Terry",
"email": "lewterry#diamond.com",
"clientServices": [
{
"id": "46",
"serviceId": "13",
"description": "Individual psychotherapy - 45 minutes",
"sessionFee": 90,
"cptCode": "90834",
"__typename": "ClientService"
}
],
"__typename": "Client"
}
}
And here's the results on a refetch after the client record is saved and the clientServices "child" data has been deleted so it's an empty array.
{
"client": {
"id": "41",
"companyId": "3",
"firstName": "Lew",
"lastName": "Terry",
"email": "lewterry#diamond.com",
clientServices: []
"__typename": "Client"
}
}
Do I really need a custom merge? Or is there another solution?
Related
I am writing a GraphQL resolver that retrieves all vertices by a particular edge using the following query (created returns label person):
software {
created {
name
}
}
Which would resolve to the following Gremlin Query for each software node found:
g.V().hasLabel('software').has('name', 'ripple').in('created')
This returns a result that includes all properties of the object:
{
"result": [
{
"#type": "d",
"#rid": "#24:0",
"#version": 6,
"#class": "person",
"in_knows": [
"#35:0"
],
"name": "josh",
"out_created": [
"#32:0",
"#33:0"
],
"age": 32,
"#fieldTypes": "in_knows=g,out_created=g"
}
],
"dbStats": {
...
}
}
I realize that this will fall foul on GraphQL's N+1 query so i'm trying to batch queries together using a Dataloader pattern. (i'm also hoping to do property selections, so i'm not asking the database to return too much info)
So i'm trying to craft a query like so:
g.V().union(
__.hasLabel('software').has('name', 'ripple').
project('parent', 'child').by('id').
by(__.in('created').fold()),
__.hasLabel('software').has('name', 'lop').
project('parent', 'child').by('id').
by(__.in('created').fold())
)
But this results in the following where the props are missing and it just includes the id of the vertices I want:
{
"result": [
{
"parent": "ripple",
"child": [
"#24:0"
]
},
{
"parent": "lop",
"child": [
"#22:0",
"#23:0",
"#24:0"
]
}
],
"dbStats": {
...
}
}
My Question is, how can I have the Gremlin query return all of the props for the found vertices and none of the other props? Should I even been doing batching this way?
For anyone else reading, the query I was trying to write wouldn't work because the TraversalSet created in the .by(_.in('created') can't be cast from a List to an ElementMap as the stream cardinality wouldn't be enforced. (You can only have one record per row, I think?)
My working query would be to duplicate the keys for each row and specify the props needed (the query below is ok for gremlin 3.3 as used in ODB, otherwise if you've got < gremlin 3.4 replace the last by step with be(elementMap('name', 'age')):
g.V().union(
__.hasLabel('software').has('name', 'ripple').
as('parent').
in('created').as('child').
select('parent', 'child').
by(values('name')).
by(properties('id', 'name', 'age').
group().by(__.key()).
by(__.value())),
__.hasLabel('software').has('name', 'lop').
as('parent').
in('created').as('child').
select('parent', 'child').
by(values('name')).
by(properties('id', 'name', 'age').
group().by(__.key()).
by(__.value()))
)
So that you get a result like this:
{"data": [
{
"parent": "ripple",
"child": {
"id": 5717,
"name": "josh",
"age": 32
}
},
{
"parent": "lop",
"child": {
"id": 5709,
"name": "peter",
"age": 35
}
},
{
"parent": "lop",
"child": {
"id": 5713,
"name": "marko",
"age": 29
}
},
{
"parent": "lop",
"child": {
"id": 5717,
"name": "josh",
"age": 32
}
}
]
}
Which would allow you to create a lookup where you concat all results for "lop" and "ripple" into arrays.
Trying to follow the example here: https://stripe.com/docs/issuing/cards/virtual
When I add params.AddExpand("number"), no number is returned, yet via the dashboard I was able to see the card numbers. Here's sample code and redacted info for the Req and Resp.
func (ac *appContext) CardRetrieve(id string) *stripe.IssuingCard {
stripe.Key = ac.Config.Stripe.SecretKey
params := stripe.IssuingCardParams{}
params.AddExpand("number")
params.AddExpand("cvc")
ic_num, _ := card.Get(id, ¶ms)
return ic_num
}
Returns:
{
"id": "ic_redacted",
"object": "issuing.card",
"brand": "Visa",
"cancellation_reason": null,
"cardholder": {
"id": "ich_redacted",
"object": "issuing.cardholder",
"billing": {
"address": {
"city": "A Beach",
"country": "US",
"line1": "404 Main St.",
"line2": "Suite #302",
"postal_code": "19001",
"state": "DE"
}
},
"company": null,
"created": 1613338532,
"email": "redacted#notreal.com",
"individual": {
"dob": {
"day": 20,
"month": 10,
"year": 1990
},
"first_name": "User",
"last_name": "Testing",
"verification": {
"document": {
"back": null,
"front": null
}
}
},
"livemode": false,
"metadata": {
},
"name": "User Testing",
"phone_number": "+15165551212",
"requirements": {
"disabled_reason": "under_review",
"past_due": [
]
},
"spending_controls": {
"allowed_categories": [
],
"blocked_categories": [
],
"spending_limits": [
{
"amount": 1,
"categories": [
],
"interval": "daily"
}
],
"spending_limits_currency": "usd"
},
"status": "active",
"type": "individual"
},
"created": 1613338532,
"currency": "usd",
"exp_month": 1,
"exp_year": 2024,
"last4": "0088",
"livemode": false,
"metadata": {
},
"replaced_by": null,
"replacement_for": null,
"replacement_reason": null,
"shipping": null,
"spending_controls": {
"allowed_categories": null,
"blocked_categories": null,
"spending_limits": [
{
"amount": 1,
"categories": [
],
"interval": "daily"
}
],
"spending_limits_currency": "usd"
},
"status": "inactive",
"type": "virtual"
}
What confuses me is the documentation found here:
https://stripe.com/docs/issuing/cards/virtual
It says: You can retrieve both the full unredacted card number and CVC from the API. For security reasons, these fields are only available for virtual cards and will be omitted unless you explicitly request them with the expand property. Additionally, they are only available through the Retrieve a card endpoint. That links to the issue card retrieval end point, but the params defined in the virtual cards example references the CardParams{} struct.
No of the examples show what imported module their aliasing for card to exec card.Get, but it stands to reason given the flow of the documentation that this should be IssuingCardParams{} and that the card alias is referencing: "github.com/stripe/stripe-go/issuing/card"
I also find it strange that we're defining params in the example but not passing it into the card.Get()
Edit:
I went digging through the module and it seems like to get the card details you have to call: details, _ := card.Details(id, params) but I get a 404 when trying to call that. The object returned is actually the right object and I see number and cvc, albeit nil.
I get the following error:
2021/02/15 00:33:06 Request error from Stripe (status 404): {"status":404,"message":"Unrecognized request URL (GET: /v1/issuing/cards/ic_redacted/details). Please see https://stripe.com/docs
So it seems you need to include a /v72 in the import:
"github.com/stripe/stripe-go/v72"
The documentation should be updated to show this and the virtual card example for go should also be updated.
This is the data in fixture file called users.json
When we access this data from Cypress how can we access as it has multiple data in under same name.
[
{
"id": 1,
"name": "Jan Test",
"username": "JTest",
"email": "SJtest#testing.com",
},
{
"id": 2,
"name": "Mark well",
"username": "Mwell",
"email": "mwell#makv.com",
},
{
"id": 3,
"name": "Geet rwar",
"username": "Grwar",
"email": "grwar#mail.com"
}
]
I suggest using Array.prototype.find(). For example
cy.fixture('users.json')
.then(array => {
const userINeed = aray.find(element => element.id === 1)
})
In this code - the array is the data from the fixture, though it needs to be in the fixtures folder
Assuming i have a class User and a class Profile
The profile class has a field called "sex" and a field called "user" which is a pointer to user class.
If i get the profile endpoint with : https://myapi.back4app.io/classes/Profile i can get the Profile object:
{
"results": [
{
"objectId": "sIE6lOZP7R",
"user": {
"__type": "Pointer",
"className": "_User",
"objectId": "asP3EFYSR4"
},
"sex": "male",
"createdAt": "2020-05-25T17:15:49.324Z",
"updatedAt": "2020-05-25T17:15:49.324Z"
}
]
}
and if i want to include the user of this profile, i can include with: https://myapi.back4app.io/classes/Perfil?include=user so i get:
{
"results": [
{
"objectId": "sIE6lOZP7R",
"user": {
"objectId": "asP3EFYSR4",
"username": "fabiojansen",
"createdAt": "2020-05-25T17:15:16.273Z",
"updatedAt": "2020-05-25T17:15:16.273Z",
"ACL": {
"*": {
"read": true
},
"asP3EFYSR4": {
"read": true,
"write": true
}
},
"__type": "Object",
"className": "_User"
},
"sex": "male",
"createdAt": "2020-05-25T17:15:49.324Z",
"updatedAt": "2020-05-25T17:15:49.324Z"
}
]
}
Its ok, but if i want to get all the users, with the profile information in one query? Its possible? In my User class, i dont have any pointer to Profile class, only in profile class.
Is there any way?
Thanks
You have several options:
1) You can use an aggregate pipeline and $lookup the user in the Perfil class which performs a LEFT JOIN. However, this will not return an array of Parse.Object, you'd have to parse the results manually. From the docs:
{
$lookup:
{
from: <collection to join>,
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>
}
}
2) You can do 2 requests by first getting all the users and then getting all their profiles by user IDs.
3) You can change your data model and add a pointer to Perfil in your User class. If you are running this query at scale it may be beneficial.
I have a spring-boot based micro-service generated using JHipster.
I am using keycloak as my Auth Server. I could enable Role-based & scope based authorization on my resources(apis).
Now the requirement is: based on the role of the client, I need to restrict the information to send in the response (either mask the attributes or nullify them).
eg:
consider the following api to get the person's profile
/api/person/{id}
{
"name": {
"firstName": "Jack",
"lastName": "Sparrow"
},
"gender": "MALE",
"emails": {
"details": [
{
"emailId": "jack.sparrow#gmail.com"
}
]
},
"phones": {
"details": [
{
"phoneNumber": "1234567890",
"countryCode": "+1"
}
]
},
"addresses": {
"details": [
{
"addressLine1": "aaaaaaaa",
"addressLine2": "bbbbbbb",
"city": "cccccc",
"state": "ddddd",
"country": "South Africa",
"postalCode": "987654"
}
]
},
"photo": "string",
"nationality": "South Africa",
"countryOfResidence": "string",
"active": true,
"createdAt": 1537431339569,
"modifiedAt": 1537436600693,
"createdBy": "admin",
"modifiedBy": "admin"
}
Now, when a person with BASIC role calls this API, the requirement is to show only basic information like:
- name, gender
If he has INTERMEDIATE role then we can send something more than basic but not full information. eg: name, gender, photo, nationality
If he has ADMIN role then we can send the complete information.
Can anyone please let me know What is the best approach to achieve this.
-- Thanks in advance :)