Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-14-2020 08:21 AM
Hello
I have been searching but cannot find a satisfactory answer on this.
Y have:
type Country {
countryId: ID
name: String!
shortName: String!
companies: [Company] @relation(name: "LOCATED_IN", direction: "IN")
}
type Company {
companyId: ID
name: String!
language: String
countries: [Country] @relation(name: "LOCATED_IN", direction: "OUT")
}
By default, mutations and queries are automatically generated.
For create:
CreateCompany(
companyId: ID
name: String!
language: String
): Company
CreateCountry(
countryId: ID
name: String!
shortName: String!
): Country
For relationship:
AddCountryCompanies(
from: _CompanyInput!
to: _CountryInput!
): _AddCountryCompaniesPayload
In this way, to generate the relationship between a Country and a Company, I must have the country created first.
Then when creating the company, it only allows me to create it, but not to create the reaction. Only after creating the company, can I create the relationship with: "AddCountryCompanies".
is it possible to nest mutation CreateCompany with AddCountryCompanies? in the same request or is it necessary to create a custom mutation?
In the latter case, what would the mutation look like:
type Mutation {
CreateCompany(
name: String!
language: String
plan: Plans
countries: [Country] @relation(name: "LOCATED_IN", direction: "OUT")
😞 Company
}
????????
04-14-2020 08:27 AM
You'll need to either chain your mutations together in the application i.e. create the new county first and then create the LOCATED_IN relationship after or write a custom mutation that will do it in one operation. To do that you'll do it just like you would if you were writing a Cypher query.
06-01-2020 11:54 AM
Perhaps I don't understand the benefits of using GraphQL for mutations in Neo4j. I thought the two main benefits were 1) Save on database I/O and network traffic and 2) Not having to write as much Cypher. Neither seems achievable. I think I'd rather just send a single post request with my Cypher for mutations.
06-01-2020 12:54 PM
That's a pretty valid want. I'd say you're essentially doing the same by writing the mutation as cyper anyway. For anything that's bigger than a single mutation I usually just write a cyper query, as a mutation, and get it done in the one request as well.
All the sessions of the conference are now available online