<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lovertab</title>
    <description>The latest articles on DEV Community by Lovertab (@lovertab).</description>
    <link>https://dev.to/lovertab</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1397994%2F9a908c92-afaf-46ff-a5f2-b0aeb63b0182.png</url>
      <title>DEV Community: Lovertab</title>
      <link>https://dev.to/lovertab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lovertab"/>
    <language>en</language>
    <item>
      <title>TypeDefs, Resolvers and Mutations</title>
      <dc:creator>Lovertab</dc:creator>
      <pubDate>Sat, 18 May 2024 03:58:04 +0000</pubDate>
      <link>https://dev.to/lovertab/typedefs-resolvers-and-mutations-cgd</link>
      <guid>https://dev.to/lovertab/typedefs-resolvers-and-mutations-cgd</guid>
      <description>&lt;p&gt;TypeDefs define the schema and structure of your GraphQL API. They specify the types of data you can query or mutate and the operations available.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijkxo9i8oz6s8mf42qm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijkxo9i8oz6s8mf42qm5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, I have five different types:&lt;br&gt;
User, which represents a user with the fields _id, username, email, and gameData.&lt;br&gt;
Auth, which represents authentication information with a token and user.&lt;br&gt;
GameData, which represents game data with fields _id, food, energy, happiness, name, createdDate, lastSaveDate, and timeAlive&lt;br&gt;
Queries:&lt;br&gt;
me which help fetches a user by their ID and &lt;br&gt;
users which fetches a list of all users.&lt;br&gt;
Next we have mutations:&lt;br&gt;
addUser, login, createGameData, deleteUser, deleteGameData, and updateGameData.&lt;/p&gt;

&lt;p&gt;Resolvers implement the logic for the operations defined in the schema. They fetch and manipulate data according to the queries and mutations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffs1er5j1t8qbat1kzqcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffs1er5j1t8qbat1kzqcx.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiaw3cs7n21j51h1ryls5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiaw3cs7n21j51h1ryls5.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Connecting Type Definitions and Resolvers&lt;br&gt;
When setting up your Apollo Server, you connect your typeDefs and resolvers.&lt;/p&gt;

&lt;p&gt;In a GraphQL API, mutations are used help change the state of the server, in this case we are using it to create, update, and delete data. The mutations I provided are using the gql function from &lt;a class="mentioned-user" href="https://dev.to/apollo"&gt;@apollo&lt;/a&gt;/client, which helps to define and send mutation requests to a GraphQL server. Each mutation is connected to specific resolvers on the server side, which handle the actual data operations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw073ooig5zgfzzy0lmed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw073ooig5zgfzzy0lmed.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faym3m0xs5not5utlqoxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faym3m0xs5not5utlqoxg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connecting to Resolvers:&lt;br&gt;
When this mutation is executed by a client, it sends a request to the GraphQL server. The server uses the defined schema to route the request to the appropriate resolver. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Many-to-Many Relationship in a Sequelize Model</title>
      <dc:creator>Lovertab</dc:creator>
      <pubDate>Thu, 16 May 2024 10:31:16 +0000</pubDate>
      <link>https://dev.to/lovertab/a-many-to-many-relationship-in-a-sequelize-model-3akb</link>
      <guid>https://dev.to/lovertab/a-many-to-many-relationship-in-a-sequelize-model-3akb</guid>
      <description>&lt;p&gt;In my recent project, I encountered the challenge of integrating a many-to-many relationship between users and anime. I decided to create a junction table, which I named "UserAnime," serving as a bridge to connect the data from both the user and anime tables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2cnf9cmmbm92sw3nv09n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2cnf9cmmbm92sw3nv09n.jpg" alt="Image description" width="800" height="1248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In choosing the file name "UserAnime," I aimed for simplicity and clarity, wanting it to reflect the nature of its purpose—to join user and anime data together. This is something a lot of developers do, and it helps not only make the file easier to identify but also helps maintain a coherent project structure.&lt;/p&gt;

&lt;p&gt;Once the junction table was established, I focused on establishing the many-to-many relationship between users and anime. This involved configuring Sequelize's association methods; in this case, I used the belongsToMany function in my index file. By defining this association, I was able to link a user to multiple animes and an anime to multiple users. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
