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

Add return types for API calls #2

Open
gouldingken opened this issue Feb 13, 2023 · 2 comments
Open

Add return types for API calls #2

gouldingken opened this issue Feb 13, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@gouldingken
Copy link
Member

To support better type safety (and code hinting) when making API calls, we should replicate the object types that are returned from the server.

It may be possible to use automatic type generation for this: https://www.apollographql.com/docs/apollo-server/workflow/generate-types/

@gouldingken gouldingken added the enhancement New feature or request label Feb 13, 2023
@gouldingken
Copy link
Member Author

For reference, here are some manually created types:

type SpeckleStreams = {
    data: {
        streams: {
            items: {
                id: string
                name: string
                updatedAt: string
            }[]
        }
    }
}

type SpeckleBranches = {
    data: {
        stream: {
            branches: {
                items: SpeckleBranch[]
            }
        }
    }
}

type SpeckleBranch = {
    commits: {
        items: SpeckleCommit[]
    }
}

type SpeckleCommit = {
    authorAvatar: string;
    authorId: string;
    authorName: string;
    branchName: string;
    createdAt: string;
    id: string;
    message: string;
    referencedObject: string;
    sourceApplication: string;
}

@gouldingken
Copy link
Member Author

Another handy utility if the GraphQL approach is too cumbersome or doesn't work:

https://jvilk.com/MakeTypes/

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

No branches or pull requests

1 participant