I am using GraphQL Express:
I am trying to run this query on relational data by property of related node:
{
Employee {
name
Item(name: "Laptop") {
name
}
}
}
But it is giving an error:
{
"errors": [
{
"message": "Unknown argument \"name\" on field \"Item\" of type \"Employee\".",
"locations": [
{
"line": 4,
"column": 10
}
]
}
]
}
Check Generated Schema Here
You can try it out here
What am I missing? Are they not supporting this kind of functionality yet?
Yes, as the error indicates there is no argument called name on the field Item.
Looks like they've got some invalid characters in their schema at the moment, which is causing issues with the GraphiQL interface loading correctly, but normally you could click on any field on the left hand side to open up the Docs panel and get additional details, including what arguments, if any, are available for it. Alternatively, you can press CTRL+SPACE or ALT+SPACE to activate the auto-complete (or just start typing).
The bigger problem is that you are using the name casing for queries as you are typesj.
You think you are trying to query all Employee types, but in fact it's hitting the Employee query which only has a name field, so Item (which should be item: Item) does not exist.
TL;DR, use capitalized strings for types, like Employee and non-capitalized names like employees to indicate a query that returns a number of Employee type instances.
Related
I'm trying to build a GraphQL query within Strapi (probably not relevant) and I'm not sure how to achieve what I want. So far I've got the following, which is close, but name_in isn't quite what I want.
query {
events(where: { audiences: { name_in: ["Year 1", "Biology"] } }) {
name
audiences {
name
}
}
}
What I'm trying to achieve is events where all of the audience names overlap with the provided query which I ultimately wish to parameterise. Here _in is obviously doing an any. So I only want records with ["Year 1"], ["Biology"] or ["Year 1", "Biology"]. Anything else such as ["Year 2", "Biology"] should not be returned as the complete set of audiences doesn't completely overlap.
Is this possible with vanilla GraphQL or do I need to start write custom resolvers?
Hi Everyone I am just trying to learn graphql as I am using Gatsby. I want to know does each field in graphql take an argument or does it need to be defined somehow before. So for example if you visit this link graphql search results
https://graphql.org/swapi-graphql?query=%7B%0A%09allPeople%20%7B%0A%09%20%20people%20%7B%0A%09%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20birthYear%0A%20%20%20%20%20%20eyeColor%0A%09%20%20%7D%0A%09%7D%0A%7D%0A
If i wanted to limit people by eye color how would I do that. In the docs it seems easy as you would just do something like people(eyecolor: 'brown') but that doesn't seem possible. Am I missing something? I basically want to do a SQL style search for all people where eye color is brown.
Thanks.
Arguments need to be defined in the schema and implemented in the resolver. If you're consuming a 3rd party API (like the link you provided), you're limited to their schema. You can tell by looking at their schema (by clicking Docs on the right side of the page) which fields take arguments. For example, person takes id and personID arguments:
people doesn't take any arguments, as seen in the schema:
If you're building your own schema, you can add arguments to any field, and when you implement the resolver for that field you can use the arguments for logic in that resolver.
If you're working with a schema that you don't control, you'll have to add filtering on the frontend:
const {people} = data.allPeople;
const brownEyedPeople = people.filter(({eyeColor}) => eyeColor === 'brown');
When you start developing in Gatsby and actually pull your data into Gatsby, there will be a filter query option that automatically becomes available in the query arguments.
https://www.gatsbyjs.org/docs/graphql-reference/#filter
You can expect to be able to filter your people by eyeColor by using the below query:
{
allPeople(filter: { eyeColor: { eq: "brown" } }) {
edges {
node {
id
name
birthYear
eyeColor
}
}
}
}
In my database (postgres) I store a table of events and each event has an "id" column which is a UUID type. But when I send a GraphQL query the id I receive back is not a string UUID but looks like some encrypted version.
I'm using Relay and Graphene on the server side if that information helps.
query {
allEvents {
edges {
node {
id
}
}
}
}
{
"data": {
"allEvents": {
"edges": [
{
"node": {
"id": "RXZlbnQ6NzRkZTIxZmUtZWQyNy00OTg1LTk2NjEtNmU4ZDUzMGEwMjQ3"
}
}
]
}
}
}
A frequent implementation choice is to base64-encode IDs and cursor values (the query you show follows Relay's pagination conventions). If you base64-decode the string you put in the question, you'll find a UUID again.
At a GraphQL level, ID is nothing more or less than an opaque ID. The spec itself doesn't say much about it, other than that it serializes as a string but could accept a number as input instead. Most more application-oriented server libraries I've worked with don't put much in the way of special semantics around ID either, like other scalar types it gets passed in and out as-is.
The last paragraph of the documentation on Relay's object identification scheme (the node top-level query) also has a strong opinion that applications shouldn't be synthesizing ID values, and so the base64 encoding at least hints to consumers that the value isn't supposed to be understood. The base64 encoding here isn't anything generic or hard-coded in GraphQL, and an application or library could choose a different ID scheme if it wanted.
I am very new to GraphQL and Apollo, and I don't understand what is wrong with the 'aliasEmail' field below. When I add this one to the query, I get this error message. When I remove it from the query, everything works perfectly.
It is well defined in 'types.graphql' and is just a simple string field.
index.js:2178 Unhandled (in react apollo:Apollo(withRouter(EmailSettingsContainer))) Error: Network
error: Error writing result to store for query:
query getCompanyForAliasEmailEditForm($companyId: ID) {
Company(id: $companyId) {
name
isTaxActive
telFixe
aliasEmail
telMobile
__typename
}
}
Store error: the application attempted to write an object with no
provided id but the store already contains an id of
Company:cje6xkcnxl83u01353a20p1t6 for this object. The selectionSet
that was trying to be written is:
Company(id: $companyId) {
name
isTaxActive
telFixe
aliasEmail
telMobile
__typename
}
It sounds like there's already another query being made elsewhere in the app that also returns the Company object and that query includes the id (or _id) field, while the query in this case does not. Apollo uses both the typename and id to generate the cache key for your query result (unless dataIdFromObject is used to modify this behavior), and so throws an error when it detects the above discrepancy. Try including the id field in your getCompanyForAliasEmailEditForm query.
I am quite new to Dynamics CRM. I am building an app which should update entity in Dynamics CRM. I can update simple types without any issues. Now the situation is, I have declared some custom Option Sets in Contact entity.
Is there any way to retrieve all the possible OptionSet values (text and value) so that my app can look for appropriate value and set it in the payload it is generating?
I can not find any endpoint in WebAPI as well as XRMServices/2011/OrganizationData.svc. Any help would be really awesome.
You can use either the Web API or Organisation Service to retrieve The metadata and data models in Microsoft Dynamics CRM. Check out the sub articles of that one for specific examples and details.
Web API example Querying EntityMetadata attributes.
The following query will return only the PicklistAttributeMetadata
attributes and will include the LogicalName as well as expanding the
OptionSet and GlobalOptionSet collection-valued navigation properties.
GET [Organization URI]/api/data/v8.1/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet
Another option would be to get the data via the StringMap entity:
[Organization URI]/api/data/v9.1/stringmaps?fetchXml=<fetch><entity name='stringmap'><filter><condition attribute='objecttypecodename' operator='in'><value>account</value><value>opportunity</value></condition></filter></entity></fetch>
Will provide data that looks like this:
{
"#odata.etag": "W/\"406742363\"",
"value": "Open",
"attributename": "statecode",
"langid": 1033,
"objecttypecode": "opportunity",
"attributevalue": 0,
"stringmapid": "0fe09734-3914-e711-80ef-e0071b6a7121",
"organizationid": "f95718b2-5c63-46df-adc3-c3b546cf686a",
"displayorder": 1
},
{
"#odata.etag": "W/\"406742364\"",
"value": "Won",
"attributename": "statecode",
"langid": 1033,
"objecttypecode": "opportunity",
"attributevalue": 1,
"stringmapid": "10e09734-3914-e711-80ef-e0071b6a7121",
"organizationid": "f95718b2-5c63-46df-adc3-c3b546cf686a",
"displayorder": 2
},
Simpler query:
[Organization URI]/api/data/v9.1/stringmaps?$filter=objecttypecode eq 'account' or objecttypecode eq 'opportunity'
If your options are global, this is the easiest way to get all options:
/api/data/v9.1/GlobalOptionSetDefinitions(Name='new_category')
Use below code to get specific option set for specific entity:
(replace EntityLogicalName and AttributeLogicalName with your input params)
GET [Organization URI]/api/data/v9.1/EntityDefinitions(LogicalName='EntityLogicalName')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)&$filter=LogicalName eq 'AttributeLogicalName'
First, you need the attribute name and type, which you can find here:
/api/data/v9.1/EntityDefinitions(LogicalName='myEntity')?$select=LogicalName&$expand=Attributes($select=LogicalName)
Replace myEntity above with your entity name. The resulting page lists all the attributes that make up your entity. Locate the desired option set attribute and note its logical name and type.
Armed with that information, go here:
/api/data/v9.1/EntityDefinitions(LogicalName='myEntity')/Attributes(LogicalName='myAttribute')/Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)
Replace myEntity and myAttribute with your entity name and attribute name, respectively. If your attribute type is not MultiSelectPicklistAttributeMetadata, replace that with the correct type that was found on the previous page. This returns a list of all the possible values for the option set (both text and numeric values).