2016-05-20 11 views
6

draftsをフェッチするGraphQLリレー接続を使用するページがあります。GraphQLリレーMutation Config接続のRANGE_ADDのparentName

query { 
    connections { 
     drafts(first: 10) { 
      edges { 
       node { 
        ... on Draft { 
         id 
        } 
       } 
      } 
     } 
    } 
} 

このページでは、CreateDraftMutationから下書きを作成します。

この突然変異の後、私はRelayが作成したドラフトをその店に追加したいと思う。

https://facebook.github.io/relay/docs/guides-mutations.html

応答ペイロードに新しく作成されたエッジの親、接続、および名前を考える

RANGE_ADD リレー追加されます:突然変異の設定のための最良の候補者は、次のように文書化されRANGE_ADD、ありますストアのノードを指定した範囲の振る舞いに従って接続に接続します。

引数

parentName:列 接続

はconnectionNameを含む親ノードのデータID:接続

PARENTIDの親を表す応答の文字列 フィールド名文字列 接続を表す応答のフィールド名

edgeName:文字列 フィールド名を

rangeBehaviors新しく作成されたエッジを表す応答:{[呼び出す:文字列]:GraphQLMutatorConstants.RANGE_OPERATIONS}

印刷、ドットで区切らGraphQLはアルファベット順に呼び出して、間のマッピングこれらの呼び出しの影響を受けて新しいエッジを接続に追加するときにRelayが表示する動作。ビヘイビアは、 'append'、 'ignore'、 'prepend'、 'refetch'、または 'remove'のいずれかになります。

次のようにドキュメントの例では、行く:

class IntroduceShipMutation extends Relay.Mutation { 
    // This mutation declares a dependency on the faction 
    // into which this ship is to be introduced. 
    static fragments = { 
    faction:() => Relay.QL`fragment on Faction { id }`, 
    }; 
    // Introducing a ship will add it to a faction's fleet, so we 
    // specify the faction's ships connection as part of the fat query. 
    getFatQuery() { 
    return Relay.QL` 
     fragment on IntroduceShipPayload { 
     faction { ships }, 
     newShipEdge, 
     } 
    `; 
    } 
    getConfigs() { 
    return [{ 
     type: 'RANGE_ADD', 
     parentName: 'faction', 
     parentID: this.props.faction.id, 
     connectionName: 'ships', 
     edgeName: 'newShipEdge', 
     rangeBehaviors: { 
     // When the ships connection is not under the influence 
     // of any call, append the ship to the end of the connection 
     '': 'append', 
     // Prepend the ship, wherever the connection is sorted by age 
     'orderby(newest)': 'prepend', 
     }, 
    }]; 
    } 
    /* ... */ 
} 

親は派閥のように明らかである場合、これはケーキの一部ですが、私はparentNameを特定苦労してとしてきましたクエリ接続から直接来た場合はparentID。

どうすればよいですか?

編集:

これは、クエリのエクスポート方法です。リターン中継コンテナ

export default Relay.createContainer(MakeRequestPage, { 
    fragments: { 
     connections:() => Relay.QL` 
      fragment on Connections { 
+0

クエリ内の 'connections'はGraphQLオブジェクトまたは接続ですか? –

+0

@AhmadFerdousBinAlam以下にスニペットを追加しました。 'Connections' GraphQLObjectTypeには、接続フィールドであるフィールドがあります。 – lustdante

答えて

1

に使用されている

export default new GraphQLObjectType({ 
    name: 'Query', 
    fields:() => ({ 
    node: nodeField, 
    viewer: { 
     type: viewerType, 
     resolve:() => ({}), 
    }, 
    connections: { 
     type: new GraphQLObjectType({ 
     name: 'Connections', 

それは クエリ接続から直接来た場合、私はparentNameとPARENTID を特定苦労してきました。リレーのドキュメントからの例では

factionships正確にあなたのケースでconnectionsdraftsと同じです。各GraphQLObjectにはIDがありますので、connectionsオブジェクトもあります。したがって、突然変異の場合、parentNameconnctionsであり、parentIDconnectionsのIDです。ところで

query { 
    connections { 
     id 
     drafts(first: 10) { 
      edges { 
       node { 
        ... on Draft { 
         id 
        } 
       } 
      } 
     } 
    } 
} 

は、私はあなたのアプリケーションドメインから connectionsdraftsある用語を推測します。そうでなければ、 connectionsはGraphQL接続タイプと混同します。

+0

'drafts'は間違いなくアプリケーションドメイン用語です。私は '接続'を実現しました。これは 'node'や' viewer'のようなよく使われるルートクエリとして扱いましたが、私たちのアプリケーションにも固有のものです。 (私のチームメイトはそれを思いついた)。ですから、接続IDはグローバルIDのようにする必要があります。 – lustdante

+0

はい、IDはグローバルIDです。 –

+0

草案が直接クエリの下にある場合、parentNameとparentIdとは何ですか? – velop

関連する問題