Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with union type #194

Merged
merged 1 commit into from
Feb 14, 2017

Conversation

sav007
Copy link
Contributor

@sav007 sav007 commented Feb 14, 2017

Closes #183

@digitalbuddha
Copy link
Contributor

digitalbuddha commented Feb 14, 2017

better but not perfect.
this works:

 {
     program(id:$id) {
       firstLoad {
         ...onBlock
       }
     }
   }

   fragment onBlock on Block {
     title
     showTitle
     showMore
     showSection
     firstLoad {
       ... onAssetsConnection
     }
     moreAssets {
       ... onAssetsConnection
     }
   }

   fragment onAssetsConnection on AssetsConnection {
     edges {
        node {
         ... assetFragment
       }
     }
   }

   fragment assetFragment on Article {
                promo_summary

   }

This does not work

query SimpleQuery($id:String!)
 {
     program(id:$id) {
       firstLoad {
         ...onBlock
       }
     }
   }

   fragment onBlock on Block {
     title
     showTitle
     showMore
     showSection
     firstLoad {
       ... onAssetsConnection
     }
     moreAssets {
       ... onAssetsConnection
     }
   }

   fragment onAssetsConnection on AssetsConnection {
     edges {
       node {

         ... on Article {
           promo_summary
         }
       }
     }
   }

@digitalbuddha
Copy link
Contributor

digitalbuddha commented Feb 14, 2017

for reference here are the IR that was generated
this is the one that does not compile

{
    "operations": [
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "operationName": "SimpleQuery",
            "operationType": "query",
            "variables": [],
            "source": "query SimpleQuery {\n  program(id: \"mobile-home\") {\n    __typename\n    firstLoad {\n      __typename\n      ...onBlock\n    }\n  }\n}",
            "fields": [
                {
                    "responseName": "program",
                    "fieldName": "program",
                    "type": "Program",
                    "args": [
                        {
                            "name": "id",
                            "value": "mobile-home"
                        }
                    ],
                    "fields": [
                        {
                            "responseName": "firstLoad",
                            "fieldName": "firstLoad",
                            "type": "[Programmable]",
                            "fields": [],
                            "fragmentSpreads": [
                                "onBlock"
                            ],
                            "inlineFragments": []
                        }
                    ],
                    "fragmentSpreads": [],
                    "inlineFragments": []
                }
            ],
            "fragmentsReferenced": [
                "onBlock",
                "onAssetsConnection"
            ]
        }
    ],
    "fragments": [
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "fragmentName": "onBlock",
            "source": "fragment onBlock on Block {\n  __typename\n  title\n  showTitle\n  showMore\n  showSection\n  firstLoad {\n    __typename\n    ...onAssetsConnection\n  }\n  moreAssets {\n    __typename\n    ...onAssetsConnection\n  }\n}",
            "typeCondition": "Block",
            "fields": [
                {
                    "responseName": "title",
                    "fieldName": "title",
                    "type": "String"
                },
                {
                    "responseName": "showTitle",
                    "fieldName": "showTitle",
                    "type": "Boolean"
                },
                {
                    "responseName": "showMore",
                    "fieldName": "showMore",
                    "type": "Boolean!"
                },
                {
                    "responseName": "showSection",
                    "fieldName": "showSection",
                    "type": "Boolean"
                },
                {
                    "responseName": "firstLoad",
                    "fieldName": "firstLoad",
                    "type": "AssetsConnection",
                    "fields": [],
                    "fragmentSpreads": [
                        "onAssetsConnection"
                    ],
                    "inlineFragments": []
                },
                {
                    "responseName": "moreAssets",
                    "fieldName": "moreAssets",
                    "type": "AssetsConnection",
                    "fields": [],
                    "fragmentSpreads": [
                        "onAssetsConnection"
                    ],
                    "inlineFragments": []
                }
            ],
            "fragmentSpreads": [],
            "inlineFragments": [],
            "fragmentsReferenced": [
                "onAssetsConnection"
            ]
        },
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "fragmentName": "onAssetsConnection",
            "source": "fragment onAssetsConnection on AssetsConnection {\n  __typename\n  edges {\n    __typename\n    node {\n      __typename\n      ... on Article {\n        __typename\n        promo_summary\n      }\n    }\n  }\n}",
            "typeCondition": "AssetsConnection",
            "fields": [
                {
                    "responseName": "edges",
                    "fieldName": "edges",
                    "type": "[AssetsEdge]",
                    "fields": [
                        {
                            "responseName": "node",
                            "fieldName": "node",
                            "type": "Asset",
                            "fields": [],
                            "fragmentSpreads": [],
                            "inlineFragments": [
                                {
                                    "typeCondition": "Article",
                                    "fields": [
                                        {
                                            "responseName": "promo_summary",
                                            "fieldName": "promo_summary",
                                            "type": "String"
                                        }
                                    ],
                                    "fragmentSpreads": []
                                }
                            ]
                        }
                    ],
                    "fragmentSpreads": [],
                    "inlineFragments": []
                }
            ],
            "fragmentSpreads": [],
            "inlineFragments": [],
            "fragmentsReferenced": []
        }
    ],
    "typesUsed": []
}

[12:17]
now this is the working one with fragments seperated:

{
    "operations": [
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "operationName": "SimpleQuery",
            "operationType": "query",
            "variables": [],
            "source": "query SimpleQuery {\n  program(id: \"mobile-home\") {\n    __typename\n    firstLoad {\n      __typename\n      ...onBlock\n    }\n  }\n}",
            "fields": [
                {
                    "responseName": "program",
                    "fieldName": "program",
                    "type": "Program",
                    "args": [
                        {
                            "name": "id",
                            "value": "mobile-home"
                        }
                    ],
                    "fields": [
                        {
                            "responseName": "firstLoad",
                            "fieldName": "firstLoad",
                            "type": "[Programmable]",
                            "fields": [],
                            "fragmentSpreads": [
                                "onBlock"
                            ],
                            "inlineFragments": []
                        }
                    ],
                    "fragmentSpreads": [],
                    "inlineFragments": []
                }
            ],
            "fragmentsReferenced": [
                "onBlock",
                "onAssetsConnection",
                "assetFragment"
            ]
        }
    ],
    "fragments": [
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "fragmentName": "onBlock",
            "source": "fragment onBlock on Block {\n  __typename\n  title\n  showTitle\n  showMore\n  showSection\n  firstLoad {\n    __typename\n    ...onAssetsConnection\n  }\n  moreAssets {\n    __typename\n    ...onAssetsConnection\n  }\n}",
            "typeCondition": "Block",
            "fields": [
                {
                    "responseName": "title",
                    "fieldName": "title",
                    "type": "String"
                },
                {
                    "responseName": "showTitle",
                    "fieldName": "showTitle",
                    "type": "Boolean"
                },
                {
                    "responseName": "showMore",
                    "fieldName": "showMore",
                    "type": "Boolean!"
                },
                {
                    "responseName": "showSection",
                    "fieldName": "showSection",
                    "type": "Boolean"
                },
                {
                    "responseName": "firstLoad",
                    "fieldName": "firstLoad",
                    "type": "AssetsConnection",
                    "fields": [],
                    "fragmentSpreads": [
                        "onAssetsConnection"
                    ],
                    "inlineFragments": []
                },
                {
                    "responseName": "moreAssets",
                    "fieldName": "moreAssets",
                    "type": "AssetsConnection",
                    "fields": [],
                    "fragmentSpreads": [
                        "onAssetsConnection"
                    ],
                    "inlineFragments": []
                }
            ],
            "fragmentSpreads": [],
            "inlineFragments": [],
            "fragmentsReferenced": [
                "onAssetsConnection",
                "assetFragment"
            ]
        },
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "fragmentName": "onAssetsConnection",
            "source": "fragment onAssetsConnection on AssetsConnection {\n  __typename\n  edges {\n    __typename\n    node {\n      __typename\n      ...assetFragment\n    }\n  }\n}",
            "typeCondition": "AssetsConnection",
            "fields": [
                {
                    "responseName": "edges",
                    "fieldName": "edges",
                    "type": "[AssetsEdge]",
                    "fields": [
                        {
                            "responseName": "node",
                            "fieldName": "node",
                            "type": "Asset",
                            "fields": [],
                            "fragmentSpreads": [
                                "assetFragment"
                            ],
                            "inlineFragments": []
                        }
                    ],
                    "fragmentSpreads": [],
                    "inlineFragments": []
                }
            ],
            "fragmentSpreads": [],
            "inlineFragments": [],
            "fragmentsReferenced": [
                "assetFragment"
            ]
        },
        {
            "filePath": "/Users/206847/apollo-android-copy/apollo-sample/src/main/graphql/com/example/foo.graphql",
            "fragmentName": "assetFragment",
            "source": "fragment assetFragment on Article {\n  __typename\n  promo_summary\n}",
            "typeCondition": "Article",
            "fields": [
                {
                    "responseName": "promo_summary",
                    "fieldName": "promo_summary",
                    "type": "String"
                }
            ],
            "fragmentSpreads": [],
            "inlineFragments": [],
            "fragmentsReferenced": []
        }
    ],
    "typesUsed": []
}

@digitalbuddha digitalbuddha merged commit 7591820 into apollographql:master Feb 14, 2017
@sav007 sav007 deleted the bug-183/union-type branch February 14, 2017 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants