paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

Error: Cannot set property 'select' of undefined #146

Closed vonphlpp closed 3 years ago

vonphlpp commented 3 years ago

Hi I created with the pal c the full-stack-nextjs project. I have to say this is really nice, didn't expect that, thx for this.

But I get the error:

ApolloError: Cannot set property 'select' of undefined
at new ApolloError (.../node_modules/@apollo/client/errors/errors.cjs.js:31:28)
                                 .../node_modules/@apollo/client/core/core.cjs.js:1438:47)

This is happening when I use getStaticProps like:

export async function getStaticProps() {
  const apolloClient = initializeApollo();

  await apolloClient.query({
    query: PAGE,
  });

  return {
    props: {
      initialApolloState: apolloClient.cache.extract(),
    },
    revalidate: 1,
  };
}

to solve this problem I made this change in src/Api/client:

function createIsomorphLink() {
  const { HttpLink } = require('@apollo/client/link/http')
  return new HttpLink({
    uri: 'http://localhost:3000/api/graphql',
    credentials: 'same-origin',
  })
}

But now I don't use anymore the SchemaLink from "@apollo/client/link/schema"

I guess I'm doing something wrong in the getStaticProps()

vonphlpp commented 3 years ago

Ok I have to use getStaticProps like:

const prisma = new PrismaClient();

export async function getStaticProps() {
  const data = await prisma.page.findMany();

  return {
    props: {
      data,
    },
    revalidate: 1,
  };
}

But now I dont have the query in my client cache. Somebody know I can save the query in the cache?

vonphlpp commented 3 years ago

Still have the Error. Please help me

import * as React from 'react';
import { Card, CardBody } from '@paljs/ui/Card';
import { Button } from '@paljs/ui/Button';
import { useRouter } from 'next/router';
import { initializeApollo } from '../Api/client';
import { gql, useQuery } from '@apollo/client';

const POSTS = gql`
  query findManyPost {
    findManyPost {
      id
    }
  }
`;

const Index = () => {
  const { data } = useQuery(POSTS);
 // query is working on the client
  console.log(data);
  ...
};

//If I use getStaticProps I get the error
export async function getStaticProps() {
  const apolloClient = initializeApollo();

  await apolloClient.query({
    query: POSTS,
  });

  return {
    props: {
      initialApolloState: apolloClient.cache.extract(),
    },
  };
}

export default Index;
AhmedElywa commented 3 years ago

This issue not in our generator please ask your question at https://stackoverflow.com/