I am wondering why my 2nd postman request does not work when utilizing variables for graphql api POST request.
The 1st request below works on Postman.
Variables with graphql issue.
query {getById(id: "2"){
id
name
icon
elements {
id name link
elements {
id name link
elements {
id name link
elements {
id name link
}
}
}
}
} }
query {getById($id: String ){
id ($id: id)
name
icon
elements {
id name link
elements {
id name link
elements {
id name link
elements {
id name link
}
}
}
}
}
}
} }
variable
{
"id": "2"
}
Your second postman request is not working because you're not having the node called "2" in the graphQL definition.
A simple breakdown of your request:
query {getById(id: "2"){
Above identifies the item with id 2 from the service.
All below that method are just nodes that you want to retrieve.
Also I think you can just use below:
query {getById($id: String ){
id
name
icon
elements {
id name link
}
}
Related
I am working on a shopify integration, and I am trying to perform some bulk queries which return data in jsonl format.
I read carefully the documentation, and I understood which is the principle behind this format, but there is one thing I don't understand: the following is a portion of my jsonl file representing the first item in the result
{"id":"gid:\/\/shopify\/Product\/6755349070004","options":[{"id":"gid:\/\/shopify\/ProductOption\/8677003133108","name":"Città ","position":1}],"title":"Product title","productType":"Concerto Live"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436363956","price":"100.00","title":"MIlano","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436396724","price":"100.00","title":"Roma","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436429492","price":"100.00","title":"Firenze","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/272323707060","description":"Product variant description","title":"CONCERTI","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/272323739828","description":"Product variant description","title":"LIVE","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/273036607668","description":"Product variant description","title":"Product variant description","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
and it's obtained by the following query
mutation {
bulkOperationRunQuery(
query: """
{
items: products{
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
variants(first: 10) {
edges {
node {
id
price
title
}
}
}
options(first: 5) {
id
name
position
}
title
collections(first: 8) {
edges {
node {
id
metafields(first: 5) {
edges {
node {
id
key
namespace
value
}
}
}
description
title
}
}
}
productType
images(first: 2) {
edges {
node {
src
}
}
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
So The first line it the "main" product object, the lines 2,3 and 4 are the variants, then we have the collections and then the image: the problem is that, besides the parent's id, there is no way to know which parent's property a child line refers to. If I want to build back a json from this, how can I know for example that the second line is an item of the array in products.variants?
You can use either:
the id format (gid://shopify/Product/6755349070004 is a product)
the __typename property that exists on all GraphQL objects
I am learning Flutter. This is the string that I need to call and I don't know how to call this type of string.
{
"Info":[
{
"c_type_id":"1",
"cleaning type":"Washroom Cleaning"
},
{
"c_type_id":"2",
"cleaning type":"Garden\/Lawn Cleaning"
}
]
}
My code
class Album {
final String title;
Album({
this.title,
});
factory Album.fromJson(Map<String, dynamic> json) {
return Album(
title: json['title'],
);
}
}
As I am following my code like this https://flutter.dev/docs/cookbook/networking/fetch-data
and got this error "A non-null String must be provided to a Text widget." because they are following this type of string and my string type is different. Help!
{
"userId": 1,
"id": 1,
"title": "quidem molestiae enim"
}
Your given data (API response) seems to have a list of maps, so you should get the data first (use async function):
var response = await http.get("Your Url")
then you should extract the given map list as follow:
var temp = json.decode(response);
List<dynamic> result = temp['Info']); // it is the described list
now, you can use your data (extract each parameter):
String c_type_id = result[0]['c_type_id'];
// and so on...
Your question is not clear at all but I can show you an example how to reach an element in a json.
Your json consists a list that contains string keys. To reach first element of list;
json["Info"][0]
Then pass the key you want to get its value;
json["Info"][0]["c_type_id"]
http_requests All type of http requests are mentioned in this post. If you have any further problem kindly make comment.
I have my message definition like
message ID {
string value = 1;
}
message User {
ID id = 1;
google.protobuf.StringValue name = 2;
}
Now if I serialize an instance of User to json, I get something like this
{
"id": {
"value" : "myid"
}
"name" : "Josh"
}
As you can see for the WKT types the value is unnested. However, for my custom message type User the value is nested. How do I make the output look like
{
"id": "myid"
"name" : "Josh"
}
I mean how do I serialize, deserialize to custom type.
One option I could think of is update this function https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/json_format.py#L199
This means, have a copy of json_format.py and extend _IsWrapperMessage to my custom types
I've been Following this post To get my head around Lazy field of T, Which I think I understand, But I'm having trouble getting associated Field Data for a Part loaded this way
Aim - To show photo of blog post author on a blog post.
I want to add a content part "Content Author"
The part Editor should appear as a drop down list of orchard users.
(regardless of the content owner cms users should be able to pick the author)
I have added an image upload field to the User Content Type
I want to show the image of the user on the front end in the view for the Content Author Part
For the first part I have created the content type and used the lazy Filed of UserPart to get the username. However when I try and get the associated fields for the UserPart. There dosent seem to be any.
public class ContentAuthorRecord : ContentPartRecord
{
public virtual string AuthorEmail { get; set; }
}
public class ContentAuthorPart : ContentPart<ContentAuthorRecord>
{
internal readonly LazyField<UserPart> Owner = new LazyField<UserPart>();
public string AuthorEmail
{
get { return Record.AuthorEmail; }
set { Record.AuthorEmail = value; }
}
public UserPart Author
{
get { return Owner.Value; }
set { Owner.Value = value; }
}
public string AuthorName
{
get
{
if (Author == null)
return "Riders for health";
else
{
return Author.UserName;
}
}
}
}
public class ContentAuthorHandler :ContentHandler
{
private readonly IContentManager _contentManager;
public ContentAuthorHandler(IRepository<ContentAuthorRecord> repository, IContentManager contentManager)
{
_contentManager = contentManager;
OnActivated<ContentAuthorPart>(SetUpCustomPart);
Filters.Add(StorageFilter.For(repository));
}
private void SetUpCustomPart(ActivatedContentContext content, ContentAuthorPart part)
{
// Setup the getter of the lazy field
part.Owner.Loader(() => _contentManager.Query<UserPart, UserPartRecord>().List().FirstOrDefault(x => x.Email == part.AuthorEmail));
}
}
I would expect to be able to access the field with something like
(ImageUploadField.Fields.ImageUploadField)Author.Fields.FirstOrDefault(x
=> x.Name == "Photo");
form the within the part class
( although this makes every thing a bit brittle, hard coding a field name, but I'm not sure how eles to go about it)
Further Info
I have a HeaderPart with a Image field added via the cms (not in code) in the display handler I fetch the field like this
protected override DriverResult Display(HeaderPart part, string displayType, dynamic shapeHelper)
{
if (part.HeaderType == HeaderType.Full_width_hero_image)
{
var field = (ImageUploadField) part.Fields.FirstOrDefault(f => f.Name == "HeaderImage");
if (field != null)
{
return ContentShape("Parts_Header_ImageHero",
() => shapeHelper.Parts_Header_ImageHero(ImagePath: field.ImagePath, ImageTitle: field.FileName));
}
return null;
}
if (part.HeaderType == HeaderType.Full_width_hero_video)
{
return ContentShape("Parts_Header_VideoHero", () => shapeHelper.Parts_Header_VideoHero(VideoUrl: part.VideoUrl));
}
if (part.HeaderType == HeaderType.Body_width_video)
{
return ContentShape("Parts_Header_VideoBody", () => shapeHelper.Parts_Header_VideoBody(VideoUrl: part.VideoUrl));
}
return null;
}
This works, But I can do the same for a part loaded into a lazy field.
Cast to dynamic first, then the syntax becomes much simpler: ((dynamic)part.ContentItem).NameOfTheType.NameOfTheField.NameOfTheProperty
If you have added the fields to the User content type via the CMS interface, it may have added the fields to a different part to the one you expect. If you are adding fields to the User content type, by default it will have added the fields to a new part called 'User', not 'UserPart'. Try to following to search all parts in the content item:
(ImageUploadField.Fields.ImageUploadField)Author.ContentItem.Parts
.SelectMany(p => p.Fields).FirstOrDefault(f => f.Name == "Photo");
or directly from the 'User' part:
(ImageUploadField.Fields.ImageUploadField)Author.ContentItem.Parts
.First(p => p.PartDefinition.Name == p.ContentItem.ContentType).Fields
.FirstOrDefault(f => f.Name == "Photo");
I have got four tables in NHibernate
Job
{
DBID { int, primary key }
Name { string }
Media { fk_media (int) }
PublishInfo { fk_publishinfo (int) }
}
Media
{
DBID { int, primary key }
TransmissionID { string }
Series { string }
Title { string }
Description { string }
}
PublishInfo
{
DBID { int, primary key }
Destination { string }
AudioTrack_1 { fk_audiolanguage }
AudioTrack_2 { fk_audiolanguage }
AudioTrack_3 { fk_audiolanguage }
AudioTrack_4 { fk_audiolanguage }
}
AudioLanguage
{
Code { string, primary key }
Description { string }
}
What I want to achive with NHibernate is that it only stores unique records. So if a Media is used multiple times they all point to the same media entry. Same goes for PublishInfo.
A second issue I ran into is that when using the same audiolanguage for audiotrack_3 and 4 for instance it gives a error that is was already used in the session.
Any tips how I would do this properly?
This is a partial anwser to my own question. The reason it wasn't working correctly for the languages when using same lanuage on multiple tracks is because they got send back and forth between a client and server application. The way I solved this is by receiving it back to the server I lookup the proper objects stored in a list on the server and replace them.
I do not think this is the proper solution but it works.