定义GraphQL架构时,获取字段类型必须是输出类型错误

时间:2017-01-06 12:40:28

标签: graphql react-starter-kit

我正在使用带有react启动工具包样板文件的快速graphql,并且在我收到错误Error: Availability.rooms field type must be Output Type but got: undefined.时尝试定义我自己的嵌套模式我采取了所有在第一个深度字段都已解决的示例 - 我更改了它使我的字段有一个嵌套字段类型并将解析移动到嵌套字段 - 但我认为我有语法错误。

schema.js

import {
  GraphQLSchema as Schema,
  GraphQLObjectType as ObjectType,
} from 'graphql';

import hotel from './queries/hotel';

const schema = new Schema({
  query: new ObjectType({
    name: 'Query',
    fields: {
      hotel,
    },
  }),
});

export default schema;

hotel.js

import {
  GraphQLObjectType as ObjectType,
  GraphQLList as List,
  GraphQLString as StringType,
  GraphQLBoolean as BooleanType,
  GraphQLInt as IntType,
  GraphQLNonNull as NonNull,
} from 'graphql';

import { checkAvailability } from './hotels';

const RoomType = new ObjectType({
  name: 'Room',
  fields: {
    name: { type: new NonNull(StringType) },
    roomTypeCategory: { type: new NonNull(StringType) },
    nights: { type: new NonNull(IntType) },
    isAvailable: { type: new NonNull(BooleanType) },
    startDate: { type: new NonNull(StringType) },
    endDate: { type: new NonNull(StringType) },
    availability: { type: new List(BooleanType) },
  },
});

const AvailabilityType = new ObjectType({
  name: 'Availability',
  args: {
    hotelId: { type: new NonNull(StringType) },
    checkIn: { type: new NonNull(StringType) },
    checkOut: { type: new NonNull(StringType) },
    numberOfAdults: { type: new NonNull(IntType) },
  },
  fields: { rooms: new List(RoomType) },
  async resolve({ request }, { hotelId, checkIn, checkOut, numberOfAdults }) {
    const rooms = await checkAvailability({
      hotelId,
      checkIn,
      checkOut,
      numberOfAdults,
    });
    return { rooms };
  },
});

export default {
  type: new ObjectType({
    name: 'Hotels',
    fields: {
      availability: { type: AvailabilityType },
    },
  }),
};

1 个答案:

答案 0 :(得分:0)

应该是:

from multiprocessing import Process, Value
import subprocess

num = Value("d", 0.0)

class foo(object):
    def __init__(self):
        self.createProcess()

    def createProcess(self):
        p = Process(target=self.Process, args=(num,))
        p.start()
        ...Do Stuff here in parallel...

    def Process(self,n):
        somebashParam = int(n.value)
        p = subprocess.Popen("some -command"+str(somebashParam),shell=True)
        out, err = p.communicate()
        n.value = p.returncode

由于字段可以获得除fields: { rooms: {type: new List(RoomType) } } (例如type)以外的更多属性,因此应传递具有resolve属性的对象。就像你为其他人做的那样。