0

次のような Api からの応答を取得しています。

property: Array(100)
0: {identifier: {…}, address: {…}, location: {…}, vintage: {…}}
1: {identifier: {…}, address: {…}, location: {…}, vintage: {…}}
2: {identifier: {…}, address: {…}, location: {…}, vintage: {…}}
3: {identifier: {…}, address: {…}, location: {…}, vintage: {…}}

たとえば、country と oneLine だけでなく、プロパティのすべてのインデックスについて、住所オブジェクトの指定されたフィールドのリストが必要です。

配列

address:
country: "US"
countrySubd: "CA"
line1: "1702 ELKHORN RD"
line2: "ROYAL OAKS, CA 95076"
locality: "Royal Oaks"
matchCode: "ExaStr"
oneLine: "1702 ELKHORN RD, ROYAL OAKS, CA 95076"
postal1: "95076"
postal2: "9218"
postal3: "R002"

これのスキーマを私のgraphqlスキーマページに書く方法について、私は2日間苦労しました。誰か助けてくれませんか?

これが私が試してきたことですが、データのnull値を取得し続けます

require("es6-promise").polyfill();
require("isomorphic-fetch");

const {
  GraphQLString,
  GraphQLList,
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLInt
} = require("graphql");



const Identifier = new GraphQLObjectType({
  name: "identifier",
  fields: () => ({
    obPropId: { type: GraphQLInt }
  })
});

const AddressType = new GraphQLObjectType({
    name: 'Address',
    fields: () => ({
        country: { type: GraphQLString },
        oneLine: {type: GraphQLString }

    })
})

const RootQuery = new GraphQLObjectType({
  name: "RootQueryType",
  fields: {
    property: {
      type: new GraphQLList(Identifier),
      resolve(parent, args) {
        return fetch(
          "https://api.gateway.attomdata.com/propertyapi/v1.0.0/property/address?postalcode=95076&page=1&pagesize=100",
          {
            headers: {
              Accept: "application/json",
              APIKey: "XXXXXXXXXXXXXXXXXXXX"
            }
          }
        )
          .then((response) => { 
            const jsonResponse = response.json();
            return jsonResponse
          }).then((jsonResonse) => console.log(JSON.stringify(jsonResonse)))
          .then(res => res.data)
          .catch(error => {
            console.log(error);
          });
      }
    }
  }
});

module.exports = new GraphQLSchema({
  query: RootQuery
});

Im running it on a express server and do my checks on localhost:5000/graphql


4

1 に答える 1