我正在制作GraphQL API,在其中我可以通过其ID检索汽车对象或在不提供任何参数的情况下检索所有汽车。
使用下面的代码,我可以通过提供id作为参数来成功检索单个汽车对象。
但是,在我希望得到对象数组的情况下,即当我完全不提供任何参数时,在GraphiQL上没有任何结果。
schema.js
let cars = [
{ name: "Honda", id: "1" },
{ name: "Toyota", id: "2" },
{ name: "BMW", id: "3" }
];
const CarType = new GraphQLObjectType({
name: "Car",
fields: () => ({
id: { type: GraphQLString },
name: { type: GraphQLString }
})
});
const RootQuery = new GraphQLObjectType({
name: "RootQueryType",
fields: {
cars: {
type: CarType,
args: {
id: { type: GraphQLString }
},
resolve(parent, args) {
if (args.id) {
console.log(cars.find(car => …Run Code Online (Sandbox Code Playgroud) 所以我正在编写一个函数,它应该交换数组的第一个和最后一个元素并返回修改后的数组.我的代码如下:
public static int[] swapEnds(int[] nums) {
int newArray[] = new int[nums.length];
newArray = nums; // copies all the elements to the new array
newArray[0] = nums[nums.length -1 ]; // changes the first element of the newArray
newArray[newArray.length-1] = nums[0]; // changes the last element of the newArray
return newArray;
}
Run Code Online (Sandbox Code Playgroud)
通过做一些调试,我发现nums [0]已经以某种方式改变了,但我没有在我的代码中的任何地方进行更改.任何帮助将非常感激.谢谢.
在观察者设计模式中,观察者观察主体和/或可观察者.观察者通过他们的更新得到通知.
我很困惑这两件事(主题和可观察的)是否基本相同?或者这两者之间有细微差别吗?
java ×2
arrays ×1
class ×1
function ×1
graphql ×1
graphql-js ×1
javascript ×1
node.js ×1
observable ×1
subject ×1
swap ×1