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

Update or expose maxDepth for telejson #9534

Closed
ArrayKnight opened this issue Jan 19, 2020 · 11 comments
Closed

Update or expose maxDepth for telejson #9534

ArrayKnight opened this issue Jan 19, 2020 · 11 comments

Comments

@ArrayKnight
Copy link

ArrayKnight commented Jan 19, 2020

Is your feature request related to a problem? Please describe.
I'm working on building an addon and when trying to pass graphql-tag DocumentNode(s) through parameters, data is lost (stringified) at a certain depth and queries are rendered useless.

Describe the solution you'd like
I'd like to be able to set the max depth (via register config?)

Describe alternatives you've considered
I also tried to avoid using the useParameter hook and to pass the parameter through the channel from decorator to panel. But it seems to have the same issue since all data in coming from the same store.

An alternative would be to find a solution that has an extreme or "infinite" max depth

Are you able to assist bring the feature to reality?
Not right now

@ArrayKnight
Copy link
Author

@stale stale bot added the inactive label Feb 10, 2020
@storybookjs storybookjs deleted a comment from stale bot Feb 10, 2020
@stale stale bot removed the inactive label Feb 10, 2020
@stale stale bot added the inactive label Mar 3, 2020
@stale stale bot closed this as completed Apr 2, 2020
@shilman
Copy link
Member

shilman commented Apr 2, 2020

cc @ndelangen @tmeasday

@ndelangen ndelangen added the todo label Apr 2, 2020
@ndelangen ndelangen reopened this Apr 2, 2020
@stale stale bot removed the inactive label Apr 2, 2020
@storybookjs storybookjs deleted a comment from stale bot Apr 2, 2020
@storybookjs storybookjs deleted a comment from stale bot Apr 2, 2020
@tmeasday
Copy link
Member

tmeasday commented Apr 7, 2020

Can you tell us a bit more about the data you are sending over @ArrayKnight?

@ndelangen
Copy link
Member

This is already possible:

const handler = function actionHandler(...args: any[]) {
const channel = addons.getChannel();
const id = uuid();
const minDepth = 5; // anything less is really just storybook internals
const actionDisplayToEmit: ActionDisplay = {
id,
count: 0,
data: { name, args },
options: {
...actionOptions,
depth: minDepth + (actionOptions.depth || 3),
allowFunction: actionOptions.allowFunction || false,
},
};
channel.emit(EVENT_ID, actionDisplayToEmit);
};
return handler;
}

if (args.length >= 1 && args[0] && args[0].options) {
options = args[0].options;
}
const handler = () => {
if (this.transport) {
this.transport.send(event, options);
}
this.handleEvent(event, true);

if (options && typeof options.allowFunction === 'boolean') {
allowFunction = options.allowFunction;
}
if (options && Number.isInteger(options.depth)) {
depth = options.depth;
}
if (options && typeof options.target === 'string') {
target = options.target;
}

@ndelangen ndelangen removed the todo label Apr 9, 2020
@ArrayKnight
Copy link
Author

ArrayKnight commented Apr 12, 2020

@tmeasday I'm sending through a DocumentNode which is created with a gql tag for a GraphQL query.

@ndelangen I'll have to give this a closer look. Is this documented anywhere?

@ArrayKnight
Copy link
Author

@ndelangen I'm seeing how you'd be able to set the depth manually for each emit but this doesn't appear to be configurable for the issue I'm having.

In a story:

import { gql } from '@apollo/client'

export default {
    ...,
    parameters: {
        myAddon: {
            foo: gql`
                {
                    artworks {
                        artist {
                            name
                            location
                        }
                        imageUrl
                        title
                    }
                }
            `
        }
    }
}

In my decorator:

export const withMyAddon: (
    options: HeadlessOptions,
) => DecoratorFunction<ReactElement<unknown>> = makeDecorator({
    name: DECORATOR_NAME,
    parameterName: PARAM_KEY,
    skipIfNoParametersOrOptions: true,
    wrapper: (storyFn, context, { options, parameters }) => {
        const channel = addons.getChannel()

        console.log(parameters) // Correctly logs full parameters without a max depth

        return (
            <Decorator
                channel={channel}
                context={context}
                options={options}
                parameters={parameters}
                storyFn={storyFn}
            />
        )
    },
})

In my panel:

export const Panel = memo(({ active }: Props): ReactElement | null => {
    const parameters = useParameter<MyAddonParameters>(PARAM_KEY, {})

    console.log(parameters) // Max depth has been applied and data is forever lost

    return <></>
})

I've been unable to find a way to configure the max depth so that the parameters maintains all data.

Now that I know about manually applying options to each message, I could in theory pass the parameters through the channel from the decorator to the panel, but that doesn't feel like what I'm supposed to do.

Also, it would be really helpful if the ...args: any somehow included the typing for an optional options object.

@ArrayKnight
Copy link
Author

@tmeasday To help clarify why I couldn't just send the query as a string over, the gql tag creates a validated editing experience that works along with a *.graphql schema file.

@ndelangen
Copy link
Member

ndelangen commented Apr 14, 2020

I see, the depth in parameters isn't enough for your usecase.

@ndelangen ndelangen reopened this Apr 14, 2020
@tmeasday
Copy link
Member

tmeasday commented May 1, 2020

@ArrayKnight you could stringify the DocumentNode yourself though and pass it as a string?

I'm sure it would be better to be able to control telejson, but essentially that'd be the same thing, no?

@ArrayKnight
Copy link
Author

That's what I'm having to do currently. But because I'm running into this issue as part of a Storybook addon, it means anybody that wants to use the addon has to do this extra step. My ideal would be to have the addon control telejson so that the end user implementation is as simple as possible.

@stale
Copy link

stale bot commented May 22, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants