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

how to build schema using TS? #38

Open
nakajimayoshi opened this issue Aug 5, 2022 · 0 comments
Open

how to build schema using TS? #38

nakajimayoshi opened this issue Aug 5, 2022 · 0 comments

Comments

@nakajimayoshi
Copy link

I'm going through the tutorial but implementing using TypeScript and tsx instead of Javascript. I'm stuck at the services/index.ts

import { request, gql, GraphQLClient } from 'graphql-request';

const graphqlAPI = process.env.GRAPHCMS_SECRET;

export const getPosts = async () => {

    const query = gql `
        query MyQuery {
            postsConnection {
                edges {
                    node {
                        author {
                            bio
                            name
                            id
                            image {
                                url
                            }
                        }
                        createdAt
                        slug
                        title
                        excerpt
                        featuredImage {
                            url
                        }
                        categories {
                            name
                            slug
                        }
                    }
                }
            }
        }
    `
    const result = await request(graphqlAPI, query);
    return result.postConnection.edges;
}

All of the fields return this error:
Unknown field "postsConnection": The parent selection or operation does not resolve to a valid schema type

and the graphqlAPI param in the return throws this error:
S2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.   Type 'undefined' is not assignable to type 'string'.

I don't know where to assign the string datatype or how to make this schema valid, it's exactly like the one in the video but this one throws error for some reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant