How to use the react-apollo.useQuery function in react-apollo

To help you get started, we’ve selected a few react-apollo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rsnay / wadayano / client / src / components / instructor / SurveyResults.js View on Github external
const SurveyResults = () => {
  const { courseId } = useParams();
  const { loading, error, data } = useQuery(COURSE_QUERY, { variables: { id: courseId } });

  const downloadCsv = () => {
    // Check that data has loaded
    if (loading || error || !data || !data.course) {
      alert('The survey data has not loaded. Please refresh the page and try again.');
    }

    const { course } = data;
    const { students } = course;
    const rows = [];

    // Header row with survey questions
    let headerRow = ['Student Name'];
    headerRow = headerRow.concat(course.survey.questions.map(q => q.prompt));
    rows.push(headerRow);
github dagster-io / dagster / js_modules / dagit / src / runs / RunsRoot.tsx View on Github external
};

  const search = tokenizedValuesFromString((qs.q as string) || "", suggestions);
  const setSearch = (search: TokenizingFieldValue[]) => {
    // Note: changing search also clears the cursor so you're back on page 1
    setCursorStack([]);
    const params = { ...qs, q: stringFromValue(search), cursor: undefined };
    history.push({ search: `?${querystring.stringify(params)}` });
  };

  const queryVars: RunsRootQueryVariables = {
    cursor: cursor,
    limit: PAGE_SIZE + 1,
    filter: runsFilterForSearchTokens(search)
  };
  const queryResult = useQuery(
    RUNS_ROOT_QUERY,
    {
      fetchPolicy: "cache-and-network",
      pollInterval: 15 * 1000,
      partialRefetch: true,
      variables: queryVars
    }
  );

  return (
github rsnay / wadayano / client / src / components / instructor / CourseList.js View on Github external
const CourseList = () => {
  const { error, data } = useQuery(INSTRUCTOR_QUERY);
  console.log(data);

  if (error) {
    return (
      
        <p>Couldn’t load courses.</p>
      
    );
  }

  if (!data || (data &amp;&amp; !data.currentInstructor)) {
    return ;
  }

  const { courses } = data.currentInstructor;
github opencollective / opencollective-frontend / components / PledgedCollectivePage.js View on Github external
const PledgedCollectivePage = ({ collective }) =&gt; {
  const { loading, error, data } = useQuery(CollectivePledgesQuery, { variables: { id: collective.id } });

  if (loading) {
    return (
      
        
      
    );
  } else if (error) {
    return (
      
        
          {error.toString()}
        
      
    );
  }
github webiny / webiny-js / packages / app-security / src / admin / views / Roles / RolesForm.js View on Github external
const RoleForm = () =&gt; {
    const scopesQuery = useQuery(LIST_SCOPES);
    const scopes = get(scopesQuery, "data.security.scopes") || [];
    const { form: crudForm } = useCrud();

    return (
        <form>
            {({ data, form, Bind }) =&gt; (
                
                    {crudForm.loading &amp;&amp; }
                    
                    
                        
                            
                                
                                    <input label="{t`Name`}">
                                
                            </form>
github terascope / teraslice / packages / ui-data-access / src / ModelForm / ModelForm.tsx View on Github external
let query: any;
    let skip: boolean = false;
    let variables: Vars | undefined;

    if (id) {
        variables = { id };
        query = config.updateQuery;
    } else if (config.createQuery) {
        query = config.createQuery;
    } else {
        query = config.updateQuery;
        skip = true;
    }

    const authUser = useCoreContext().authUser!;
    const { loading, error, data, client } = useQuery(query, {
        variables,
        skip,
    });

    if (loading) return ;
    if (error) return ;

    const props = config.handleFormProps(authUser, data || {});

    return (
        
            
                client={client}
                {...passThroughProps}
                {...props}
                modelName={modelName}
github terascope / teraslice / packages / ui-data-access / src / ModelList / Query.tsx View on Github external
if (state.size) state.size = toNumber(state.size);
        if (state.from) state.from = toNumber(state.from);

        const updateQueryState = (updates: QueryState) =&gt; {
            history.push({
                search: stringify({ ...state, ...updates }),
            });
        };

        const variables = {
            ...state,
            query: formatRegexQuery(state.query || '', searchFields),
        };

        const { loading, error, data } = useQuery(listQuery, {
            variables,
            fetchPolicy: 'cache-and-network',
        });

        if (error) return ;
        if (!data &amp;&amp; !loading) {
            return ;
        }

        const records = (data &amp;&amp; data.records) || [];
        const total = (data &amp;&amp; data.total) || 0;

        return (
github ensdomains / ens-app / src / components / SingleName / ResolverAndRecords / ResolverAndRecords.js View on Github external
export default function ResolverAndRecords({
  domain,
  isOwner,
  refetch,
  account
}) {
  const hasResolver = hasAResolver(domain.resolver)
  let isOldPublicResolver = false
  let isDeprecatedResolver = false
  let areRecordsMigrated = true

  const { data, loading } = useQuery(GET_RESOLVER_MIGRATION_INFO, {
    variables: {
      name: domain.name,
      resolver: domain.resolver
    },
    skip: !hasResolver
  })

  if (data && data.getResolverMigrationInfo) {
    isOldPublicResolver = data.getResolverMigrationInfo.isOldPublicResolver
    isDeprecatedResolver = data.getResolverMigrationInfo.isDeprecatedResolver
    areRecordsMigrated = data.getResolverMigrationInfo.areRecordsMigrated
  }

  const needsToBeMigrated =
    !loading && (isOldPublicResolver || isDeprecatedResolver)
github seashell / drago / ui / src / views / interfaces / details / index.js View on Github external
},
    validationSchema: Yup.object().shape({
      name: Yup.string()
        .required()
        .nullable(),
      networkId: Yup.string().nullable(),
      ipAddress: Yup.string().nullable(),
      listenPort: Yup.number()
        .positive()
        .nullable(),
    }),
  })

  const getNetworksQuery = useQuery(GET_NETWORKS)

  const getInterfaceQuery = useQuery(GET_INTERFACE, {
    variables: { id: urlParams.interfaceId },
    fetchPolicy: 'cache-and-network',
    onCompleted: data => {
      formik.setValues(
        {
          name: data.result.name,
          networkId: data.result.networkId,
          ipAddress: data.result.ipAddress,
          listenPort: data.result.listenPort,
        },
        true
      )
    },
    onError: () => {
      toast.error('Error fetching interface details')
      navigate(-1)
github dagster-io / dagster / js_modules / dagit / src / App.tsx View on Github external
export const App: React.FunctionComponent = () =&gt; {
  const result = useQuery(ROOT_PIPELINES_QUERY, {
    fetchPolicy: "cache-and-network"
  });
  const { pipelines, error } = extractData(result.data);

  return (
    
      
      {error ? (
        
      ) : (
        
      )}