sasakiassociates / speckle

JavaScript client for the Speckle API
15 stars 1 forks source link

Add return types for API calls #2

Open gouldingken opened 1 year ago

gouldingken commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

https://jvilk.com/MakeTypes/