{
2705 | this._ref = ref;
2706 | }}
2707 | style={{
2708 | fontSize: 12,
2709 | textOverflow: 'ellipsis',
2710 | whiteSpace: 'nowrap',
2711 | margin: 0,
2712 | padding: 8,
2713 | fontFamily:
2714 | 'Consolas, Inconsolata, "Droid Sans Mono", Monaco, monospace',
2715 | display: 'flex',
2716 | flexDirection: 'column',
2717 | height: '100%',
2718 | }}
2719 | className="graphiql-explorer-root">
2720 |
2725 | {relevantOperations.map(
2726 | (
2727 | operation: OperationDefinitionNode | FragmentDefinitionNode,
2728 | index,
2729 | ) => {
2730 | const operationName =
2731 | operation && operation.name && operation.name.value;
2732 |
2733 | const operationType =
2734 | operation.kind === 'FragmentDefinition'
2735 | ? 'fragment'
2736 | : (operation && operation.operation) || 'query';
2737 |
2738 | const onOperationRename = newName => {
2739 | const newOperationDef = renameOperation(operation, newName);
2740 | this.props.onEdit(print(newOperationDef));
2741 | };
2742 |
2743 | const onOperationClone = () => {
2744 | const newOperationDef = cloneOperation(operation);
2745 | this.props.onEdit(print(newOperationDef));
2746 | };
2747 |
2748 | const onOperationDestroy = () => {
2749 | const newOperationDef = destroyOperation(operation);
2750 | this.props.onEdit(print(newOperationDef));
2751 | };
2752 |
2753 | const fragmentType =
2754 | operation.kind === 'FragmentDefinition' &&
2755 | operation.typeCondition.kind === 'NamedType' &&
2756 | schema.getType(operation.typeCondition.name.value);
2757 |
2758 | const fragmentFields =
2759 | fragmentType instanceof GraphQLObjectType
2760 | ? fragmentType.getFields()
2761 | : null;
2762 |
2763 | const fields =
2764 | operationType === 'query'
2765 | ? queryFields
2766 | : operationType === 'mutation'
2767 | ? mutationFields
2768 | : operationType === 'subscription'
2769 | ? subscriptionFields
2770 | : operation.kind === 'FragmentDefinition'
2771 | ? fragmentFields
2772 | : null;
2773 |
2774 | const fragmentTypeName =
2775 | operation.kind === 'FragmentDefinition'
2776 | ? operation.typeCondition.name.value
2777 | : null;
2778 |
2779 | const onCommit = (parsedDocument: DocumentNode) => {
2780 | const textualNewDocument = print(parsedDocument);
2781 |
2782 | this.props.onEdit(textualNewDocument);
2783 | };
2784 |
2785 | return (
2786 | {
2803 | let commit;
2804 | if (
2805 | typeof options === 'object' &&
2806 | typeof options.commit !== 'undefined'
2807 | ) {
2808 | commit = options.commit;
2809 | } else {
2810 | commit = true;
2811 | }
2812 |
2813 | if (!!newDefinition) {
2814 | const newQuery: DocumentNode = {
2815 | ...parsedQuery,
2816 | definitions: parsedQuery.definitions.map(
2817 | existingDefinition =>
2818 | existingDefinition === operation
2819 | ? newDefinition
2820 | : existingDefinition,
2821 | ),
2822 | };
2823 |
2824 | if (commit) {
2825 | onCommit(newQuery);
2826 | return newQuery;
2827 | } else {
2828 | return newQuery;
2829 | }
2830 | } else {
2831 | return parsedQuery;
2832 | }
2833 | }}
2834 | schema={schema}
2835 | getDefaultFieldNames={getDefaultFieldNames}
2836 | getDefaultScalarArgValue={getDefaultScalarArgValue}
2837 | makeDefaultArg={makeDefaultArg}
2838 | onRunOperation={() => {
2839 | if (!!this.props.onRunOperation) {
2840 | this.props.onRunOperation(operationName);
2841 | }
2842 | }}
2843 | styleConfig={styleConfig}
2844 | availableFragments={availableFragments}
2845 | />
2846 | );
2847 | },
2848 | )}
2849 | {attribution}
2850 |
2851 |
2852 | {actionsEl}
2853 |
2854 | );
2855 | }
2856 | }
2857 |
2858 | class ErrorBoundary extends React.Component<
2859 | *,
2860 | {hasError: boolean, error: any, errorInfo: any},
2861 | > {
2862 | state = {hasError: false, error: null, errorInfo: null};
2863 |
2864 | componentDidCatch(error, errorInfo) {
2865 | this.setState({hasError: true, error: error, errorInfo: errorInfo});
2866 | console.error('Error in component', error, errorInfo);
2867 | }
2868 |
2869 | render() {
2870 | if (this.state.hasError) {
2871 | return (
2872 |