var numSides = 6; var numRolls = 3; var xhr = new XMLHttpRequest(); xhr.responseType = ‘json‘; xhr.open("POST", "http://localhost:4000/graphql"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("Accept", "application/json"); xhr.onload = function () { console.log(‘data returned:‘, xhr.response); } var query = `query getDiexx($numSides:Int!,$numRolls:Int!) { getDie(numSides: $numSides) { numSides roll(numRolls: $numRolls) } }`; xhr.send(JSON.stringify({ query: query, variables: {numSides: numSides, numRolls: numRolls}, }));
时间: 2024-11-08 23:29:58