Skip to content

Commit 512fcf6

Browse files
authored
Merge pull request #2050 from apollographql/union-interface-types
Add `unionTypes` and `interfaceTypes` to the `json-modern` IR
2 parents df046b1 + 54c60ed commit 512fcf6

7 files changed

Lines changed: 461 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- `apollo-codegen-typescript`
1414
- <First `apollo-codegen-typescript` related entry goes here>
1515
- `apollo-codegen-core`
16-
- <First `apollo-codegen-core` related entry goes here>
16+
- Add new `unionTypes` and `interfaceTypes` properties to the exported IR JSON (when using the `json-modern` target), that list all unions and their types, as well as all interfaces and their implementing types [#2050](https://github.com/apollographql/apollo-tooling/pull/2050).
1717
- `apollo-env`
1818
- <First `apollo-env` related entry goes here>
1919
- `apollo-graphql`

packages/apollo-codegen-core/src/__tests__/__snapshots__/jsonOutput.ts.snap

Lines changed: 297 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ exports[`JSON output should generate JSON output for a mutation with an enum and
151151
}
152152
]
153153
}
154-
]
154+
],
155+
\\"unionTypes\\": [],
156+
\\"interfaceTypes\\": []
155157
}"
156158
`;
157159

@@ -300,7 +302,17 @@ exports[`JSON output should generate JSON output for a query with a fragment spr
300302
]
301303
}
302304
],
303-
\\"typesUsed\\": []
305+
\\"typesUsed\\": [],
306+
\\"unionTypes\\": [],
307+
\\"interfaceTypes\\": [
308+
{
309+
\\"name\\": \\"Character\\",
310+
\\"types\\": [
311+
\\"Human\\",
312+
\\"Droid\\"
313+
]
314+
}
315+
]
304316
}"
305317
`;
306318

@@ -377,7 +389,17 @@ exports[`JSON output should generate JSON output for a query with a nested selec
377389
}
378390
],
379391
\\"fragments\\": [],
380-
\\"typesUsed\\": []
392+
\\"typesUsed\\": [],
393+
\\"unionTypes\\": [],
394+
\\"interfaceTypes\\": [
395+
{
396+
\\"name\\": \\"Character\\",
397+
\\"types\\": [
398+
\\"Human\\",
399+
\\"Droid\\"
400+
]
401+
}
402+
]
381403
}"
382404
`;
383405

@@ -468,6 +490,16 @@ exports[`JSON output should generate JSON output for a query with an enum variab
468490
}
469491
]
470492
}
493+
],
494+
\\"unionTypes\\": [],
495+
\\"interfaceTypes\\": [
496+
{
497+
\\"name\\": \\"Character\\",
498+
\\"types\\": [
499+
\\"Human\\",
500+
\\"Droid\\"
501+
]
502+
}
471503
]
472504
}"
473505
`;
@@ -538,7 +570,9 @@ exports[`JSON output should generate JSON output for a subscription 1`] = `
538570
}
539571
],
540572
\\"fragments\\": [],
541-
\\"typesUsed\\": []
573+
\\"typesUsed\\": [],
574+
\\"unionTypes\\": [],
575+
\\"interfaceTypes\\": []
542576
}"
543577
`;
544578

@@ -658,6 +692,265 @@ exports[`JSON output should generate JSON output for an input object type with d
658692
}
659693
]
660694
}
695+
],
696+
\\"unionTypes\\": [],
697+
\\"interfaceTypes\\": []
698+
}"
699+
`;
700+
701+
exports[`JSON output should list all interfaces and their implementing types under a \`interfaceTypes\` property 1`] = `
702+
"{
703+
\\"operations\\": [
704+
{
705+
\\"filePath\\": \\"GraphQL request\\",
706+
\\"operationName\\": \\"HeroForEpisode\\",
707+
\\"operationType\\": \\"query\\",
708+
\\"rootType\\": \\"Query\\",
709+
\\"variables\\": [],
710+
\\"source\\": \\"query HeroForEpisode {\\\\n hero(episode: JEDI) {\\\\n __typename\\\\n name\\\\n ... on Droid {\\\\n primaryFunction\\\\n }\\\\n }\\\\n}\\",
711+
\\"fields\\": [
712+
{
713+
\\"responseName\\": \\"hero\\",
714+
\\"fieldName\\": \\"hero\\",
715+
\\"type\\": \\"Character\\",
716+
\\"args\\": [
717+
{
718+
\\"name\\": \\"episode\\",
719+
\\"value\\": \\"JEDI\\",
720+
\\"type\\": \\"Episode\\"
721+
}
722+
],
723+
\\"isConditional\\": false,
724+
\\"isDeprecated\\": false,
725+
\\"fields\\": [
726+
{
727+
\\"responseName\\": \\"__typename\\",
728+
\\"fieldName\\": \\"__typename\\",
729+
\\"type\\": \\"String!\\",
730+
\\"isConditional\\": false,
731+
\\"isDeprecated\\": false
732+
},
733+
{
734+
\\"responseName\\": \\"name\\",
735+
\\"fieldName\\": \\"name\\",
736+
\\"type\\": \\"String!\\",
737+
\\"isConditional\\": false,
738+
\\"description\\": \\"The name of the character\\",
739+
\\"isDeprecated\\": false
740+
}
741+
],
742+
\\"fragmentSpreads\\": [],
743+
\\"inlineFragments\\": [
744+
{
745+
\\"typeCondition\\": \\"Droid\\",
746+
\\"possibleTypes\\": [
747+
\\"Droid\\"
748+
],
749+
\\"fields\\": [
750+
{
751+
\\"responseName\\": \\"__typename\\",
752+
\\"fieldName\\": \\"__typename\\",
753+
\\"type\\": \\"String!\\",
754+
\\"isConditional\\": false,
755+
\\"isDeprecated\\": false
756+
},
757+
{
758+
\\"responseName\\": \\"name\\",
759+
\\"fieldName\\": \\"name\\",
760+
\\"type\\": \\"String!\\",
761+
\\"isConditional\\": false,
762+
\\"description\\": \\"What others call this droid\\",
763+
\\"isDeprecated\\": false
764+
},
765+
{
766+
\\"responseName\\": \\"primaryFunction\\",
767+
\\"fieldName\\": \\"primaryFunction\\",
768+
\\"type\\": \\"String\\",
769+
\\"isConditional\\": false,
770+
\\"description\\": \\"This droid's primary function\\",
771+
\\"isDeprecated\\": false
772+
}
773+
],
774+
\\"fragmentSpreads\\": []
775+
}
776+
]
777+
}
778+
],
779+
\\"fragmentSpreads\\": [],
780+
\\"inlineFragments\\": [],
781+
\\"fragmentsReferenced\\": [],
782+
\\"sourceWithFragments\\": \\"query HeroForEpisode {\\\\n hero(episode: JEDI) {\\\\n __typename\\\\n name\\\\n ... on Droid {\\\\n primaryFunction\\\\n }\\\\n }\\\\n}\\",
783+
\\"operationId\\": \\"173a7ebf41abd014f3fc54ddd007f6182fca738bd44a1e2d1bb75503c8bf79f6\\"
784+
}
785+
],
786+
\\"fragments\\": [],
787+
\\"typesUsed\\": [],
788+
\\"unionTypes\\": [],
789+
\\"interfaceTypes\\": [
790+
{
791+
\\"name\\": \\"Character\\",
792+
\\"types\\": [
793+
\\"Human\\",
794+
\\"Droid\\"
795+
]
796+
}
661797
]
662798
}"
663799
`;
800+
801+
exports[`JSON output should list all unions and their types under a \`unionTypes\` property 1`] = `
802+
"{
803+
\\"operations\\": [
804+
{
805+
\\"filePath\\": \\"GraphQL request\\",
806+
\\"operationName\\": \\"Search\\",
807+
\\"operationType\\": \\"query\\",
808+
\\"rootType\\": \\"Query\\",
809+
\\"variables\\": [],
810+
\\"source\\": \\"query Search {\\\\n search(text: \\\\\\"an\\\\\\") {\\\\n __typename\\\\n ... on Human {\\\\n name\\\\n height\\\\n }\\\\n ... on Droid {\\\\n name\\\\n primaryFunction\\\\n }\\\\n ... on Starship {\\\\n name\\\\n length\\\\n }\\\\n }\\\\n}\\",
811+
\\"fields\\": [
812+
{
813+
\\"responseName\\": \\"search\\",
814+
\\"fieldName\\": \\"search\\",
815+
\\"type\\": \\"[SearchResult]\\",
816+
\\"args\\": [
817+
{
818+
\\"name\\": \\"text\\",
819+
\\"value\\": \\"an\\",
820+
\\"type\\": \\"String\\"
821+
}
822+
],
823+
\\"isConditional\\": false,
824+
\\"isDeprecated\\": false,
825+
\\"fields\\": [
826+
{
827+
\\"responseName\\": \\"__typename\\",
828+
\\"fieldName\\": \\"__typename\\",
829+
\\"type\\": \\"String!\\",
830+
\\"isConditional\\": false,
831+
\\"isDeprecated\\": false
832+
}
833+
],
834+
\\"fragmentSpreads\\": [],
835+
\\"inlineFragments\\": [
836+
{
837+
\\"typeCondition\\": \\"Human\\",
838+
\\"possibleTypes\\": [
839+
\\"Human\\"
840+
],
841+
\\"fields\\": [
842+
{
843+
\\"responseName\\": \\"__typename\\",
844+
\\"fieldName\\": \\"__typename\\",
845+
\\"type\\": \\"String!\\",
846+
\\"isConditional\\": false,
847+
\\"isDeprecated\\": false
848+
},
849+
{
850+
\\"responseName\\": \\"name\\",
851+
\\"fieldName\\": \\"name\\",
852+
\\"type\\": \\"String!\\",
853+
\\"isConditional\\": false,
854+
\\"description\\": \\"What this human calls themselves\\",
855+
\\"isDeprecated\\": false
856+
},
857+
{
858+
\\"responseName\\": \\"height\\",
859+
\\"fieldName\\": \\"height\\",
860+
\\"type\\": \\"Float\\",
861+
\\"isConditional\\": false,
862+
\\"description\\": \\"Height in the preferred unit, default is meters\\",
863+
\\"isDeprecated\\": false
864+
}
865+
],
866+
\\"fragmentSpreads\\": []
867+
},
868+
{
869+
\\"typeCondition\\": \\"Droid\\",
870+
\\"possibleTypes\\": [
871+
\\"Droid\\"
872+
],
873+
\\"fields\\": [
874+
{
875+
\\"responseName\\": \\"__typename\\",
876+
\\"fieldName\\": \\"__typename\\",
877+
\\"type\\": \\"String!\\",
878+
\\"isConditional\\": false,
879+
\\"isDeprecated\\": false
880+
},
881+
{
882+
\\"responseName\\": \\"name\\",
883+
\\"fieldName\\": \\"name\\",
884+
\\"type\\": \\"String!\\",
885+
\\"isConditional\\": false,
886+
\\"description\\": \\"What others call this droid\\",
887+
\\"isDeprecated\\": false
888+
},
889+
{
890+
\\"responseName\\": \\"primaryFunction\\",
891+
\\"fieldName\\": \\"primaryFunction\\",
892+
\\"type\\": \\"String\\",
893+
\\"isConditional\\": false,
894+
\\"description\\": \\"This droid's primary function\\",
895+
\\"isDeprecated\\": false
896+
}
897+
],
898+
\\"fragmentSpreads\\": []
899+
},
900+
{
901+
\\"typeCondition\\": \\"Starship\\",
902+
\\"possibleTypes\\": [
903+
\\"Starship\\"
904+
],
905+
\\"fields\\": [
906+
{
907+
\\"responseName\\": \\"__typename\\",
908+
\\"fieldName\\": \\"__typename\\",
909+
\\"type\\": \\"String!\\",
910+
\\"isConditional\\": false,
911+
\\"isDeprecated\\": false
912+
},
913+
{
914+
\\"responseName\\": \\"name\\",
915+
\\"fieldName\\": \\"name\\",
916+
\\"type\\": \\"String!\\",
917+
\\"isConditional\\": false,
918+
\\"description\\": \\"The name of the starship\\",
919+
\\"isDeprecated\\": false
920+
},
921+
{
922+
\\"responseName\\": \\"length\\",
923+
\\"fieldName\\": \\"length\\",
924+
\\"type\\": \\"Float\\",
925+
\\"isConditional\\": false,
926+
\\"description\\": \\"Length of the starship, along the longest axis\\",
927+
\\"isDeprecated\\": false
928+
}
929+
],
930+
\\"fragmentSpreads\\": []
931+
}
932+
]
933+
}
934+
],
935+
\\"fragmentSpreads\\": [],
936+
\\"inlineFragments\\": [],
937+
\\"fragmentsReferenced\\": [],
938+
\\"sourceWithFragments\\": \\"query Search {\\\\n search(text: \\\\\\"an\\\\\\") {\\\\n __typename\\\\n ... on Human {\\\\n name\\\\n height\\\\n }\\\\n ... on Droid {\\\\n name\\\\n primaryFunction\\\\n }\\\\n ... on Starship {\\\\n name\\\\n length\\\\n }\\\\n }\\\\n}\\",
939+
\\"operationId\\": \\"9887ff0652e14d678a66769b853c41293d4afb1d1338bbbdb9f84e66979605dd\\"
940+
}
941+
],
942+
\\"fragments\\": [],
943+
\\"typesUsed\\": [],
944+
\\"unionTypes\\": [
945+
{
946+
\\"name\\": \\"SearchResult\\",
947+
\\"types\\": [
948+
\\"Human\\",
949+
\\"Droid\\",
950+
\\"Starship\\"
951+
]
952+
}
953+
],
954+
\\"interfaceTypes\\": []
955+
}"
956+
`;

0 commit comments

Comments
 (0)