I am still learning dGraphQL so I’m not sure this is even possible. I have the two types defined in my schema. The three non-required fields of the Coordinate type need to be required for for the Cooridor type. I know the ! makes it a required field, but can you make fields required in one type when they are not required in another?
I hope that makes sense.
Sure, the required predicates in Coordinate do not effect required predicates in other types. But I think maybe you’re asking something different. Care to elaborate? Example inserts go a long way in helping to understand what you’re asking…
Hi Matt,
I may not have explained what I want to do properly. And I don’t have any data yet, just trying to create a schema to get an understanding of what all the parts mean and do.
So in the code in the post, I list three different types: coordinate, point, corridor. For the Coordinate type, I want any time it is used it has to have the lon and lat fields. I believe this is done by the ! at the end of the statement. Now you can see that the Point type has a coordinate field and I am requiring that to be filled in. When this type (Point) fills in the coordinate field, the field has to have the coordinate.lon and coordinate.lat fields filled in. I am still working through the mutation syntax. I have the standalone dgraph installed but the gui interface for it only accepts DQL format. So I apologize if this doesn’t make sense.
This mutation for adding a point is done like this because the lat and lon are required in the Coordinate type. For the Point type the hae, ce, and le fields are left empty and ignored by the Point type. So adding a Point to the graph will not throw an error if the hae, ce, and le fields are not filled in.
Now the corridor type also must have the hae, ce, and le fields filled in with a value in addition to the lat and lon fields. This is where I am not sure if it can be done. Here is a rough mutation example:
mutation addCorridor {
“type”:“corridor”
“point”: {
“coordinates”: {
“lon”: -118.98333333333333
“lat”: 46.46777654
“hae”: 8543.4
“ce”: 9999999
“le”: 9999999
}
}
}
Now when adding a Corridor object to the graph would be similar but it would require the hae, le, and ce fields of the Coordinate type. So now the add method would fail if the hae, ce, and le fields of the Coordinate type were not given a value.
Looking at this again though, I don’t think I can accomplish what I am trying to do with how i setup the types. Since Corridor type has a Point type instead of a Coordinate type I can’t make the fields required since it is going to go through the Point type when setting up the coordinates field.
Still not 100% clear on what you’re asking… I suggest you just try some schemas and mutations.
Try this URL in your browser: https://studio.apollographql.com/sandbox/explorer?endpoint=http://localhost:8080/graphqllink
Or, if you’d prefer to not deal locally with Dgraph, open a free cloud instance at cloud.dgraph.io. The dashboard there allows one to interact with both DQL and GraphQL.