GraphQL create mutations performing nested relation creations return values

I think I’ve butchered that title. Oh well.

I have a dataset creation query/function/mutation(?) that looks like the following:

mutation CreateADataset($DataStuff: DataStuffInput!, $IDStuff: IDStuffInput, $InfoStuff: InfoStuffInput){
	createDataset(data: {
		DataStuff: $DataStuff
		IDStuff: {
			create: $IDStuff
		}
		InfoStuff: {
			create: $InfoStuff
		}
	}){
		DataStuff{
			DataStuffResults
		}
		IDStuff{
			IDStuffID
		}
		InfoStuff{
			InfoStuffInfo
		}
	} 
}

My problem is that I need to connect the “IDStuff” and “InfoStuff”, but the return value for this mutation does not include the _id's of any of the 3 newly created datasets.
Is there a way to have this function return the _id's of these 3 newly created items?

With how difficult this has become it makes me wonder if my approach to this schema or approach to creating these datasets are flawed. Any help is greatly appreciated.

Hi @Skewjo. Can you please share your Schema?

@ptpaterson
Sure!
This isn’t the actual schema, but I’ve edited it to match the example I provided above:

type Dataset { 
    DataStuff: DataStuff!
    IDStuff: IDStuff @relation(name: "dataSetOwnerIDStuff")
    InfoStuff: InfoStuff @relation(name: "dataSetOwnerInfoStuff")
}

type DataStuff @embedded { 
    DataStuffResults: [Int!]
}

type IDStuff{
    Dataset: [Dataset!] @relation(name: "dataSetOwnerIDStuff")
    InfoStuff: InfoStuff @relation(name: "ID_of_InfoStuff")
    IDStuffID: String! @unique
}

type InfoStuff{
    Dataset: [Dataset!] @relation(name: "dataSetOwnerInfoStuff")
	IDStuff: IDStuff @relation(name: "ID_of_InfoStuff")
    InfoStuffInfo: String!
}

type Query {   
    AllDatasets: [Dataset!]
    IDStuffByID(IDStuffID: String): IDStuff
    AllIDStuffs: [IDStuff!]
    AllInfoStuffs: [InfoStuff!]
}

I am not seeing anything obvious that would be wrong in the schema.

I uploaded it and entered in a mutation. It sent back all of the _id's

Are you trying to also link the IDStuff document and the InfoStuff document directly to each other? For that, you would need to “connect” them in a second query, or create them first and then connect them to the Dataset document.

Also, if it wasn’t clear, you do have to request the _id field, just like any other field. I.e. it doesn’t come automatically.

1 Like

Thanks @ptpaterson!

IDK why, but I had it in my mind that the requested info at the bottom was specifying which fields to mutate. This fixed me right up.